Codeforces-SolutionsA/Codes/1846C Rudolf and the Another Competition/1846C.cpp

61 lines
1.0 KiB
C++
Raw Normal View History

2023-08-03 04:42:39 +08:00
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll n,m,h;
cin>>n>>m>>h;
vector<ll>solved;
vector<ll>penalty;
ll rs, rp;
for(ll i=0; i<n; ++i)
{
vector<ll>a;
for(ll j=0; j<m; ++j)
{
ll x;
cin>>x;
a.push_back(x);
}
sort(a.begin(),a.end());
ll time=0,pen=0,ct=0;
for(ll x:a)
{
time=time+x;
if(h>=time)
{
ct++;
pen=pen+time;
}
}
if(i==0)
{
rs=ct;
rp=pen;
}
solved.push_back(ct);
penalty.push_back(pen);
}
ll pos=1;
for(ll i=1; i<n; ++i)
{
if(solved[i]>rs) pos++;
else if(solved[i]==rs)
{
if(penalty[i]<rp) pos++;
}
}
cout<<pos<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll TC = 1;
cin >> TC;
cin.ignore();
while (TC--) solve();
}