Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n;
- struct lucrare {
- unsigned int h, p, cod;
- } v[1000];
- void ord() {
- for (int i = 0; i < n - 1; i++)
- for (int j = i + 1; j < n; j++)
- if (v[i].h > v[j].h)
- swap(v[i], v[j]);
- else if (v[i].h == v[j].h)
- if (v[i].p < v[j].p)
- swap(v[i], v[j]);
- }
- void greedy() {
- cout << v[0].cod << " ";
- int s = 0;
- for (int i = 1; i < n; i++)
- if (v[i].h == v[i - 1].h)
- s += v[i].p;
- else
- cout << v[i].cod << " ";
- cout << endl << "suma penalizarilor " << s;
- }
- void citire() {
- cout << "n=";
- cin >> n;
- for (int i = 0; i < n; i++) {
- cout << "Ora ";
- cin >> v[i].h;
- cout << "Penalizare ";
- cin >> v[i].p;
- v[i].cod = i + 1;
- }
- }
- int main() {
- citire();
- ord();
- greedy();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement