#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sz(a) (int)(a.size())
int n,k;
vector<ll>s[2001];
vector<ll>comb(vector<ll>a,vector<ll>b,ll x){
int p = 0,q = 0;
vector<ll>c;
while(p != sz(a) || q != sz(b)){
if(p==sz(a) || a[p] > b[q]+x){
c.push_back(b[q]+x);
q++;
}else{
c.push_back(a[p]);
p++;
}
}
while(sz(c) > k)c.pop_back();
return c;
}
int main()
{
cin>>n>>k;
vector<array<ll,2>>v(n);
s[0] = {0};
for(int i=0;i<n;i++)cin>>v[i][1]>>v[i][0];
sort(v.begin(),v.end());
for(int i=0;i<n;i++){
for(int j=n;j;j--){
if(!sz(s[j-1]))continue;
if(v[i][0] >= j)s[j] = comb(s[j],s[j-1],v[i][1]);
}
}
int cnt = 0;
for(int j=n;j>=1;j--){
if(cnt==k)break;
for(ll x:s[j]){
cout<<j<<" "<<x<<'\n';
cnt++;
if(cnt==k)break;
}
}
while(cnt < k){
cnt++;
cout<<0<<" "<<0<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
460 KB |
Output is correct |
2 |
Correct |
216 ms |
408 KB |
Output is correct |
3 |
Correct |
175 ms |
388 KB |
Output is correct |
4 |
Correct |
224 ms |
500 KB |
Output is correct |
5 |
Correct |
209 ms |
532 KB |
Output is correct |
6 |
Correct |
4 ms |
368 KB |
Output is correct |
7 |
Correct |
6 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
8 ms |
332 KB |
Output is correct |
10 |
Correct |
53 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
460 KB |
Output is correct |
2 |
Correct |
216 ms |
408 KB |
Output is correct |
3 |
Correct |
175 ms |
388 KB |
Output is correct |
4 |
Correct |
224 ms |
500 KB |
Output is correct |
5 |
Correct |
209 ms |
532 KB |
Output is correct |
6 |
Correct |
4 ms |
368 KB |
Output is correct |
7 |
Correct |
6 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
8 ms |
332 KB |
Output is correct |
10 |
Correct |
53 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Runtime error |
2 ms |
1096 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1004 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
968 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
968 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
460 KB |
Output is correct |
2 |
Correct |
216 ms |
408 KB |
Output is correct |
3 |
Correct |
175 ms |
388 KB |
Output is correct |
4 |
Correct |
224 ms |
500 KB |
Output is correct |
5 |
Correct |
209 ms |
532 KB |
Output is correct |
6 |
Correct |
4 ms |
368 KB |
Output is correct |
7 |
Correct |
6 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
8 ms |
332 KB |
Output is correct |
10 |
Correct |
53 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Runtime error |
2 ms |
1096 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |