#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=2e3+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
vl dp[N][N];
pair<int,int> t[N];
vl comb(vl a,vl b){
int w1=0,w2=0;
vl res;
while(w1<a.size() and w2<b.size()){
if(a[w1]<b[w2]) res.push_back(a[w1]),w1++;
else res.push_back(b[w2]),w2++;
}
for(int i=w1;i<a.size();i++) res.push_back(a[i]);
for(int i=w2;i<b.size();i++) res.push_back(b[i]);
return res;
}
void solve(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>t[i].fi>>t[i].se;
sort(t+1,t+1+n,[](pair<int,int> a,pair<int,int> b){
return a.se<b.se;
});
dp[0][0].push_back(0);
for(int i=1;i<=n;i++){
int aktsum=0;
for(int j=max(0,t[i].se-i);j<=t[i].se;j++){
if(j-(t[i].se-t[i-1].se)+1<0) continue;
if(j-(t[i].se-t[i-1].se)<0){
dp[i][j]=dp[i-1][j-(t[i].se-t[i-1].se)+1];
for(auto &u:dp[i][j]) u+=(ll)t[i].fi;
}else{
vl pom=dp[i-1][j-(t[i].se-t[i-1].se)+1];
for(auto &u:pom) u+=(ll)t[i].fi;
dp[i][j]=comb(dp[i-1][j-(t[i].se-t[i-1].se)],pom);
}
aktsum+=dp[i][j].size();
while(aktsum>k) dp[i][j].pop_back(),aktsum--;
}
}
for(int i=max(0,t[n].se-n);i<=t[n].se;i++){
for(auto u:dp[n][i]) cout<<t[n].se-i<<" "<<u<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
while(tt--) solve();
}
Compilation message
Main.cpp: In function 'vl comb(vl, vl)':
Main.cpp:25:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | while(w1<a.size() and w2<b.size()){
| ~~^~~~~~~~~
Main.cpp:25:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | while(w1<a.size() and w2<b.size()){
| ~~^~~~~~~~~
Main.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=w1;i<a.size();i++) res.push_back(a[i]);
| ~^~~~~~~~~
Main.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=w2;i<b.size();i++) res.push_back(b[i]);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
95448 KB |
Output is correct |
2 |
Correct |
80 ms |
95276 KB |
Output is correct |
3 |
Correct |
72 ms |
95316 KB |
Output is correct |
4 |
Correct |
76 ms |
95328 KB |
Output is correct |
5 |
Correct |
89 ms |
95364 KB |
Output is correct |
6 |
Correct |
54 ms |
95204 KB |
Output is correct |
7 |
Correct |
51 ms |
95200 KB |
Output is correct |
8 |
Correct |
44 ms |
95256 KB |
Output is correct |
9 |
Correct |
45 ms |
95240 KB |
Output is correct |
10 |
Correct |
60 ms |
95260 KB |
Output is correct |
11 |
Correct |
46 ms |
95132 KB |
Output is correct |
12 |
Correct |
51 ms |
95084 KB |
Output is correct |
13 |
Correct |
45 ms |
95080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
95448 KB |
Output is correct |
2 |
Correct |
80 ms |
95276 KB |
Output is correct |
3 |
Correct |
72 ms |
95316 KB |
Output is correct |
4 |
Correct |
76 ms |
95328 KB |
Output is correct |
5 |
Correct |
89 ms |
95364 KB |
Output is correct |
6 |
Correct |
54 ms |
95204 KB |
Output is correct |
7 |
Correct |
51 ms |
95200 KB |
Output is correct |
8 |
Correct |
44 ms |
95256 KB |
Output is correct |
9 |
Correct |
45 ms |
95240 KB |
Output is correct |
10 |
Correct |
60 ms |
95260 KB |
Output is correct |
11 |
Correct |
46 ms |
95132 KB |
Output is correct |
12 |
Correct |
51 ms |
95084 KB |
Output is correct |
13 |
Correct |
45 ms |
95080 KB |
Output is correct |
14 |
Incorrect |
89 ms |
95336 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
95304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
95548 KB |
Output is correct |
2 |
Correct |
50 ms |
95684 KB |
Output is correct |
3 |
Correct |
50 ms |
95536 KB |
Output is correct |
4 |
Correct |
47 ms |
95548 KB |
Output is correct |
5 |
Correct |
47 ms |
95616 KB |
Output is correct |
6 |
Correct |
48 ms |
95172 KB |
Output is correct |
7 |
Incorrect |
52 ms |
95436 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
95348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
95448 KB |
Output is correct |
2 |
Correct |
80 ms |
95276 KB |
Output is correct |
3 |
Correct |
72 ms |
95316 KB |
Output is correct |
4 |
Correct |
76 ms |
95328 KB |
Output is correct |
5 |
Correct |
89 ms |
95364 KB |
Output is correct |
6 |
Correct |
54 ms |
95204 KB |
Output is correct |
7 |
Correct |
51 ms |
95200 KB |
Output is correct |
8 |
Correct |
44 ms |
95256 KB |
Output is correct |
9 |
Correct |
45 ms |
95240 KB |
Output is correct |
10 |
Correct |
60 ms |
95260 KB |
Output is correct |
11 |
Correct |
46 ms |
95132 KB |
Output is correct |
12 |
Correct |
51 ms |
95084 KB |
Output is correct |
13 |
Correct |
45 ms |
95080 KB |
Output is correct |
14 |
Incorrect |
89 ms |
95336 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |