Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- #define ppb pop_back
- int main()
- {
- _test
- {
- int n, m, h;
- cin>>n>>m>>h;
- vector<vector<int>> t(n, vector<int> (m));
- for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin>>t[i][j];
- vector<pair<ll int, ll int>> p;
- for(auto &e: t) sort(e.begin(), e.end());
- for(int i=1; i<n; i++)
- {
- ll int tot = 0;
- ll int c = 0;
- ll int sum = 0;
- for(auto e: t[i])
- {
- sum += e;
- if(sum > h) break;
- tot += sum;
- c--;
- }
- p.pb({c, tot});
- }
- ll int tot = 0;
- ll int c = 0;
- ll int sum = 0;
- for(auto e: t[0])
- {
- sum += e;
- if(sum > h) break;
- tot += sum;
- c--;
- }
- sort(p.begin(), p.end());
- while(p.size() && (p.back() >= make_pair(c, tot)))
- p.ppb();
- cout<<p.size()+1<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment