Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool f(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
    if (a.first.first > b.first.first)
        return true;
    if (a.first.first == b.first.first)
    {
        if (a.first.second < b.first.second)
            return true;
        else if (a.first.second == b.first.second)
        {
            if(a.second < b.second)
            return true;
            else 
            return false;
        }
        else
            return false;
    }
    else
        return false;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n, m, h;
        cin >> n >> m >> h;
        vector<pair<pair<int, int>, int>> a;
        for (int i = 0; i < n; i++)
        {
            vector<int> temp(m);
            for (int j = 0; j < m; j++)
                cin >> temp[j];
            sort(temp.begin(), temp.end());
            for (int j = 1; j < m; j++)
                temp[j] = temp[j] + temp[j - 1];
            int count = 0;
            int penalty = 0;
            for (int j = 0; j < m; j++)
            {
                /* code */ if (temp[j] <= h)
                {
                    count++;
                    penalty += temp[j];
                }
            }
            a.push_back({{count, penalty}, i + 1});
        }
        sort(a.begin(), a.end(), f);
       //
        for (int i = 0; i < n; i++)
        {
            if (a[i].second == 1)
                cout << (i + 1);
            /* code */
        }
        cout << '\n';
    }

    return 0;
}