This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k,ans=0;
cin>>n>>k;
if(k>1)
{
long long r[n][k],u[n][k];
for(int i=0;i<n;i++)
for(int j=0;j<k;j++)
cin>>r[i][j];
for(int i=0;i<n;i++)
for(int j=0;j<k;j++)
cin>>u[i][j];
long long p[k]={0};bool used[n]={0};
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(used[j])continue;
bool check=1;
for(int g=0;g<k;g++)
if(p[g]<r[j][g]){check=0;break;}
if(check)
{
used[j]=1;
ans++;
for(int g=0;g<k;g++)
p[g]+=u[j][g];
}
}
cout<<ans;
}
else
{
vector<pair<long long,long long>>ru;
long long r[n],u[n];
for(int i=0;i<n;i++)cin>>r[i];
for(int i=0;i<n;i++)cin>>u[i];
for(int i=0;i<n;i++)
ru.push_back({r[i],u[i]});
sort(ru.begin(),ru.end());
long long p=0;
for(int i=0;i<n;i++)
{
if(ru[i].first<=p)
{
ans++;
p+=ru[i].second;
continue;
}
else break;
}
cout<<ans;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |