#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
588 KB |
Output is correct |
4 |
Correct |
399 ms |
23732 KB |
Output is correct |
5 |
Correct |
418 ms |
23740 KB |
Output is correct |
6 |
Correct |
392 ms |
23764 KB |
Output is correct |
7 |
Correct |
263 ms |
23888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
580 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
6 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
860 KB |
Output is correct |
4 |
Correct |
55 ms |
4136 KB |
Output is correct |
5 |
Correct |
49 ms |
4036 KB |
Output is correct |
6 |
Correct |
550 ms |
32548 KB |
Output is correct |
7 |
Correct |
499 ms |
33464 KB |
Output is correct |
8 |
Correct |
558 ms |
32544 KB |
Output is correct |
9 |
Correct |
536 ms |
34100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
588 KB |
Output is correct |
4 |
Correct |
399 ms |
23732 KB |
Output is correct |
5 |
Correct |
418 ms |
23740 KB |
Output is correct |
6 |
Correct |
392 ms |
23764 KB |
Output is correct |
7 |
Correct |
263 ms |
23888 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
348 KB |
Output is correct |
15 |
Correct |
6 ms |
580 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
348 KB |
Output is correct |
19 |
Correct |
6 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
860 KB |
Output is correct |
23 |
Correct |
55 ms |
4136 KB |
Output is correct |
24 |
Correct |
49 ms |
4036 KB |
Output is correct |
25 |
Correct |
550 ms |
32548 KB |
Output is correct |
26 |
Correct |
499 ms |
33464 KB |
Output is correct |
27 |
Correct |
558 ms |
32544 KB |
Output is correct |
28 |
Correct |
536 ms |
34100 KB |
Output is correct |
29 |
Correct |
539 ms |
34076 KB |
Output is correct |
30 |
Correct |
566 ms |
33360 KB |
Output is correct |
31 |
Execution timed out |
1016 ms |
31028 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |