#include <bits/stdc++.h>
#pragma optimize("O3")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ve vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define si(v) (int)v.size()
#define en '\n'
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_muiltiset tree<int, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>
//#define int long long
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e3 + 228;
const int big = 1e9 + 228;
const ll llbig = 1e18 + 228;
//ordered_set os; // os.order_of_key(4), (*os.find_by_order(5))
int n, m, ans, k;
pair<ll, ll> a[N];
priority_queue<ll> dp[N][N];
bool cmp(pair<ll, ll> a, pair<ll, ll> b){
if (a.se <= b.se) return 1;
return 0;
}
void upd(ll &a, ll b){
if (a > b) {a = b;}
}
//#undef int
int main(){
//#define int long long
iostream::sync_with_stdio(false); cin.tie(0); ios_base::sync_with_stdio(false); cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> a[i].fi >> a[i].se;
}
stable_sort(a + 1, a + n + 1, cmp);
dp[0][0].push(0);
for (int i = 0; i < n; i++){
for (int j = 0; j <= n; j++){
for (int g = 1; g <= k; g++){
if (dp[i][j].empty()) break;
ll cur = dp[i][j].top(); dp[i][j].pop();
dp[i + 1][j].push(cur);
if (j + 1 <= a[i + 1].se) dp[i + 1][j + 1].push(cur - a[i + 1].fi);
}
}
}
set<pair<ll, ll>> ans;
for (int j = 1; j <= n; j++) {
for (int g = 1; g <= k; g++){
if (dp[n][j].empty()) break;
ans.insert({-j, -dp[n][j].top()});
dp[n][j].pop();
}
}
int kol = 0;
for (auto item : ans){
kol++;
if (kol > k) break;
cout << -item.fi << ' ' << item.se << en;
}
if (kol <= k){
for (int i = kol + 1; i <= k; i++) cout << 0 << ' ' << 0 << en;
}
return 0;
}
/*
*/
Compilation message
Main.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize("O3")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
212748 KB |
Output is correct |
2 |
Correct |
259 ms |
216644 KB |
Output is correct |
3 |
Correct |
273 ms |
206280 KB |
Output is correct |
4 |
Correct |
229 ms |
207176 KB |
Output is correct |
5 |
Correct |
269 ms |
215696 KB |
Output is correct |
6 |
Correct |
89 ms |
155824 KB |
Output is correct |
7 |
Correct |
91 ms |
156128 KB |
Output is correct |
8 |
Correct |
84 ms |
155980 KB |
Output is correct |
9 |
Correct |
88 ms |
157016 KB |
Output is correct |
10 |
Correct |
122 ms |
169132 KB |
Output is correct |
11 |
Correct |
73 ms |
155652 KB |
Output is correct |
12 |
Correct |
88 ms |
155624 KB |
Output is correct |
13 |
Correct |
72 ms |
155720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
212748 KB |
Output is correct |
2 |
Correct |
259 ms |
216644 KB |
Output is correct |
3 |
Correct |
273 ms |
206280 KB |
Output is correct |
4 |
Correct |
229 ms |
207176 KB |
Output is correct |
5 |
Correct |
269 ms |
215696 KB |
Output is correct |
6 |
Correct |
89 ms |
155824 KB |
Output is correct |
7 |
Correct |
91 ms |
156128 KB |
Output is correct |
8 |
Correct |
84 ms |
155980 KB |
Output is correct |
9 |
Correct |
88 ms |
157016 KB |
Output is correct |
10 |
Correct |
122 ms |
169132 KB |
Output is correct |
11 |
Correct |
73 ms |
155652 KB |
Output is correct |
12 |
Correct |
88 ms |
155624 KB |
Output is correct |
13 |
Correct |
72 ms |
155720 KB |
Output is correct |
14 |
Correct |
233 ms |
212768 KB |
Output is correct |
15 |
Correct |
320 ms |
216704 KB |
Output is correct |
16 |
Correct |
216 ms |
206296 KB |
Output is correct |
17 |
Correct |
284 ms |
207192 KB |
Output is correct |
18 |
Correct |
247 ms |
215624 KB |
Output is correct |
19 |
Correct |
83 ms |
155792 KB |
Output is correct |
20 |
Correct |
87 ms |
156056 KB |
Output is correct |
21 |
Correct |
88 ms |
155924 KB |
Output is correct |
22 |
Correct |
92 ms |
156968 KB |
Output is correct |
23 |
Correct |
137 ms |
169280 KB |
Output is correct |
24 |
Correct |
81 ms |
155720 KB |
Output is correct |
25 |
Correct |
81 ms |
155624 KB |
Output is correct |
26 |
Correct |
83 ms |
155720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
361 ms |
241332 KB |
Output is correct |
2 |
Correct |
350 ms |
247076 KB |
Output is correct |
3 |
Correct |
329 ms |
231640 KB |
Output is correct |
4 |
Correct |
344 ms |
232852 KB |
Output is correct |
5 |
Correct |
432 ms |
245720 KB |
Output is correct |
6 |
Correct |
100 ms |
155920 KB |
Output is correct |
7 |
Correct |
84 ms |
156240 KB |
Output is correct |
8 |
Correct |
115 ms |
156096 KB |
Output is correct |
9 |
Correct |
102 ms |
157636 KB |
Output is correct |
10 |
Correct |
180 ms |
176008 KB |
Output is correct |
11 |
Correct |
84 ms |
155728 KB |
Output is correct |
12 |
Correct |
86 ms |
155728 KB |
Output is correct |
13 |
Correct |
83 ms |
155700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
159092 KB |
Output is correct |
2 |
Correct |
105 ms |
159360 KB |
Output is correct |
3 |
Correct |
94 ms |
158496 KB |
Output is correct |
4 |
Correct |
87 ms |
157948 KB |
Output is correct |
5 |
Correct |
108 ms |
159528 KB |
Output is correct |
6 |
Correct |
80 ms |
155612 KB |
Output is correct |
7 |
Correct |
81 ms |
156556 KB |
Output is correct |
8 |
Correct |
84 ms |
156044 KB |
Output is correct |
9 |
Correct |
81 ms |
155948 KB |
Output is correct |
10 |
Correct |
99 ms |
155732 KB |
Output is correct |
11 |
Correct |
79 ms |
155612 KB |
Output is correct |
12 |
Correct |
76 ms |
155652 KB |
Output is correct |
13 |
Correct |
91 ms |
158252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
165128 KB |
Output is correct |
2 |
Correct |
119 ms |
164952 KB |
Output is correct |
3 |
Correct |
96 ms |
163448 KB |
Output is correct |
4 |
Correct |
97 ms |
163228 KB |
Output is correct |
5 |
Correct |
118 ms |
164816 KB |
Output is correct |
6 |
Correct |
103 ms |
155700 KB |
Output is correct |
7 |
Correct |
83 ms |
156440 KB |
Output is correct |
8 |
Correct |
78 ms |
156040 KB |
Output is correct |
9 |
Correct |
84 ms |
156484 KB |
Output is correct |
10 |
Correct |
85 ms |
158308 KB |
Output is correct |
11 |
Correct |
79 ms |
155628 KB |
Output is correct |
12 |
Correct |
79 ms |
155596 KB |
Output is correct |
13 |
Correct |
79 ms |
157616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
212748 KB |
Output is correct |
2 |
Correct |
259 ms |
216644 KB |
Output is correct |
3 |
Correct |
273 ms |
206280 KB |
Output is correct |
4 |
Correct |
229 ms |
207176 KB |
Output is correct |
5 |
Correct |
269 ms |
215696 KB |
Output is correct |
6 |
Correct |
89 ms |
155824 KB |
Output is correct |
7 |
Correct |
91 ms |
156128 KB |
Output is correct |
8 |
Correct |
84 ms |
155980 KB |
Output is correct |
9 |
Correct |
88 ms |
157016 KB |
Output is correct |
10 |
Correct |
122 ms |
169132 KB |
Output is correct |
11 |
Correct |
73 ms |
155652 KB |
Output is correct |
12 |
Correct |
88 ms |
155624 KB |
Output is correct |
13 |
Correct |
72 ms |
155720 KB |
Output is correct |
14 |
Correct |
233 ms |
212768 KB |
Output is correct |
15 |
Correct |
320 ms |
216704 KB |
Output is correct |
16 |
Correct |
216 ms |
206296 KB |
Output is correct |
17 |
Correct |
284 ms |
207192 KB |
Output is correct |
18 |
Correct |
247 ms |
215624 KB |
Output is correct |
19 |
Correct |
83 ms |
155792 KB |
Output is correct |
20 |
Correct |
87 ms |
156056 KB |
Output is correct |
21 |
Correct |
88 ms |
155924 KB |
Output is correct |
22 |
Correct |
92 ms |
156968 KB |
Output is correct |
23 |
Correct |
137 ms |
169280 KB |
Output is correct |
24 |
Correct |
81 ms |
155720 KB |
Output is correct |
25 |
Correct |
81 ms |
155624 KB |
Output is correct |
26 |
Correct |
83 ms |
155720 KB |
Output is correct |
27 |
Correct |
361 ms |
241332 KB |
Output is correct |
28 |
Correct |
350 ms |
247076 KB |
Output is correct |
29 |
Correct |
329 ms |
231640 KB |
Output is correct |
30 |
Correct |
344 ms |
232852 KB |
Output is correct |
31 |
Correct |
432 ms |
245720 KB |
Output is correct |
32 |
Correct |
100 ms |
155920 KB |
Output is correct |
33 |
Correct |
84 ms |
156240 KB |
Output is correct |
34 |
Correct |
115 ms |
156096 KB |
Output is correct |
35 |
Correct |
102 ms |
157636 KB |
Output is correct |
36 |
Correct |
180 ms |
176008 KB |
Output is correct |
37 |
Correct |
84 ms |
155728 KB |
Output is correct |
38 |
Correct |
86 ms |
155728 KB |
Output is correct |
39 |
Correct |
83 ms |
155700 KB |
Output is correct |
40 |
Correct |
99 ms |
159092 KB |
Output is correct |
41 |
Correct |
105 ms |
159360 KB |
Output is correct |
42 |
Correct |
94 ms |
158496 KB |
Output is correct |
43 |
Correct |
87 ms |
157948 KB |
Output is correct |
44 |
Correct |
108 ms |
159528 KB |
Output is correct |
45 |
Correct |
80 ms |
155612 KB |
Output is correct |
46 |
Correct |
81 ms |
156556 KB |
Output is correct |
47 |
Correct |
84 ms |
156044 KB |
Output is correct |
48 |
Correct |
81 ms |
155948 KB |
Output is correct |
49 |
Correct |
99 ms |
155732 KB |
Output is correct |
50 |
Correct |
79 ms |
155612 KB |
Output is correct |
51 |
Correct |
76 ms |
155652 KB |
Output is correct |
52 |
Correct |
91 ms |
158252 KB |
Output is correct |
53 |
Correct |
101 ms |
165128 KB |
Output is correct |
54 |
Correct |
119 ms |
164952 KB |
Output is correct |
55 |
Correct |
96 ms |
163448 KB |
Output is correct |
56 |
Correct |
97 ms |
163228 KB |
Output is correct |
57 |
Correct |
118 ms |
164816 KB |
Output is correct |
58 |
Correct |
103 ms |
155700 KB |
Output is correct |
59 |
Correct |
83 ms |
156440 KB |
Output is correct |
60 |
Correct |
78 ms |
156040 KB |
Output is correct |
61 |
Correct |
84 ms |
156484 KB |
Output is correct |
62 |
Correct |
85 ms |
158308 KB |
Output is correct |
63 |
Correct |
79 ms |
155628 KB |
Output is correct |
64 |
Correct |
79 ms |
155596 KB |
Output is correct |
65 |
Correct |
79 ms |
157616 KB |
Output is correct |
66 |
Runtime error |
1640 ms |
524292 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |