Education + Jobs Hiring Website - 2025
1 like 0 dislike
447 views

in Online Assessments by Expert (139,860 points) | 447 views

1 Answer

0 like 0 dislike
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q;
    if (!(cin >> n >> q)) return 0;

    vector<vector<int>> a(n, vector<int>(q, 0));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < q; j++) {
            cin >> a[i][j];
        }
    }

    int inventory;
    cin >> inventory;

    sort(a.begin(), a.end(), [](const vector<int>& row1, const vector<int>& row2) {
        return row1[2] > row2[2];
    });

    int i = 0;

    while (i < n && inventory >= a[i][1]) {
        inventory -= a[i][1];
        i++;
    }

    for (int j = i+1; j < n; j++) {
        cout << a[j][0] << " ";
    }
    cout << "\n";

    return 0;
}
ago by (150 points)