#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];
set<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].insert(0);
for (int i = 0; i < n; i++){
for (int j = 0; j <= n; j++){
while(si(dp[i][j]) > k) dp[i][j].erase(--dp[i][j].end());
for (auto item : dp[i][j]){
dp[i + 1][j].insert(item);
}
if (j + 1 <= a[i + 1].se) {
for (auto item : dp[i][j]){
dp[i + 1][j + 1].insert(item + a[i + 1].fi);
}
}
}
}
set<pair<ll, ll>> ans;
for (int j = 1; j <= n; j++) {
for (auto item : dp[n][j]){
ans.insert({-j, item});
}
}
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 |
235 ms |
318952 KB |
Output is correct |
2 |
Correct |
245 ms |
324784 KB |
Output is correct |
3 |
Correct |
224 ms |
309392 KB |
Output is correct |
4 |
Correct |
219 ms |
310552 KB |
Output is correct |
5 |
Correct |
247 ms |
323268 KB |
Output is correct |
6 |
Correct |
116 ms |
233640 KB |
Output is correct |
7 |
Correct |
124 ms |
234020 KB |
Output is correct |
8 |
Correct |
141 ms |
233804 KB |
Output is correct |
9 |
Correct |
129 ms |
235380 KB |
Output is correct |
10 |
Correct |
145 ms |
253588 KB |
Output is correct |
11 |
Correct |
101 ms |
233404 KB |
Output is correct |
12 |
Correct |
109 ms |
233348 KB |
Output is correct |
13 |
Correct |
101 ms |
233448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
235 ms |
318952 KB |
Output is correct |
2 |
Correct |
245 ms |
324784 KB |
Output is correct |
3 |
Correct |
224 ms |
309392 KB |
Output is correct |
4 |
Correct |
219 ms |
310552 KB |
Output is correct |
5 |
Correct |
247 ms |
323268 KB |
Output is correct |
6 |
Correct |
116 ms |
233640 KB |
Output is correct |
7 |
Correct |
124 ms |
234020 KB |
Output is correct |
8 |
Correct |
141 ms |
233804 KB |
Output is correct |
9 |
Correct |
129 ms |
235380 KB |
Output is correct |
10 |
Correct |
145 ms |
253588 KB |
Output is correct |
11 |
Correct |
101 ms |
233404 KB |
Output is correct |
12 |
Correct |
109 ms |
233348 KB |
Output is correct |
13 |
Correct |
101 ms |
233448 KB |
Output is correct |
14 |
Correct |
294 ms |
319196 KB |
Output is correct |
15 |
Correct |
306 ms |
324972 KB |
Output is correct |
16 |
Correct |
282 ms |
309444 KB |
Output is correct |
17 |
Correct |
386 ms |
310732 KB |
Output is correct |
18 |
Correct |
298 ms |
323424 KB |
Output is correct |
19 |
Correct |
136 ms |
233616 KB |
Output is correct |
20 |
Correct |
123 ms |
233980 KB |
Output is correct |
21 |
Correct |
115 ms |
233796 KB |
Output is correct |
22 |
Correct |
118 ms |
235312 KB |
Output is correct |
23 |
Correct |
204 ms |
253732 KB |
Output is correct |
24 |
Correct |
105 ms |
233388 KB |
Output is correct |
25 |
Correct |
105 ms |
233436 KB |
Output is correct |
26 |
Correct |
110 ms |
233392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
507 ms |
404828 KB |
Output is correct |
2 |
Correct |
534 ms |
416488 KB |
Output is correct |
3 |
Correct |
467 ms |
385452 KB |
Output is correct |
4 |
Correct |
478 ms |
387908 KB |
Output is correct |
5 |
Correct |
526 ms |
413508 KB |
Output is correct |
6 |
Correct |
115 ms |
233704 KB |
Output is correct |
7 |
Correct |
124 ms |
234540 KB |
Output is correct |
8 |
Correct |
121 ms |
234048 KB |
Output is correct |
9 |
Correct |
123 ms |
237224 KB |
Output is correct |
10 |
Correct |
233 ms |
273988 KB |
Output is correct |
11 |
Correct |
124 ms |
233312 KB |
Output is correct |
12 |
Correct |
104 ms |
233428 KB |
Output is correct |
13 |
Correct |
103 ms |
233540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
243516 KB |
Output is correct |
2 |
Correct |
158 ms |
243772 KB |
Output is correct |
3 |
Correct |
128 ms |
241348 KB |
Output is correct |
4 |
Correct |
122 ms |
239800 KB |
Output is correct |
5 |
Correct |
144 ms |
244576 KB |
Output is correct |
6 |
Correct |
101 ms |
233420 KB |
Output is correct |
7 |
Correct |
113 ms |
235976 KB |
Output is correct |
8 |
Correct |
113 ms |
234264 KB |
Output is correct |
9 |
Correct |
135 ms |
234024 KB |
Output is correct |
10 |
Correct |
121 ms |
233368 KB |
Output is correct |
11 |
Correct |
104 ms |
233412 KB |
Output is correct |
12 |
Correct |
103 ms |
233344 KB |
Output is correct |
13 |
Correct |
149 ms |
240720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
255008 KB |
Output is correct |
2 |
Correct |
230 ms |
254312 KB |
Output is correct |
3 |
Correct |
197 ms |
251144 KB |
Output is correct |
4 |
Correct |
174 ms |
250928 KB |
Output is correct |
5 |
Correct |
198 ms |
255108 KB |
Output is correct |
6 |
Correct |
122 ms |
233572 KB |
Output is correct |
7 |
Correct |
111 ms |
235452 KB |
Output is correct |
8 |
Correct |
108 ms |
234348 KB |
Output is correct |
9 |
Correct |
112 ms |
235284 KB |
Output is correct |
10 |
Correct |
154 ms |
239128 KB |
Output is correct |
11 |
Correct |
107 ms |
233484 KB |
Output is correct |
12 |
Correct |
104 ms |
233412 KB |
Output is correct |
13 |
Correct |
124 ms |
237864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
235 ms |
318952 KB |
Output is correct |
2 |
Correct |
245 ms |
324784 KB |
Output is correct |
3 |
Correct |
224 ms |
309392 KB |
Output is correct |
4 |
Correct |
219 ms |
310552 KB |
Output is correct |
5 |
Correct |
247 ms |
323268 KB |
Output is correct |
6 |
Correct |
116 ms |
233640 KB |
Output is correct |
7 |
Correct |
124 ms |
234020 KB |
Output is correct |
8 |
Correct |
141 ms |
233804 KB |
Output is correct |
9 |
Correct |
129 ms |
235380 KB |
Output is correct |
10 |
Correct |
145 ms |
253588 KB |
Output is correct |
11 |
Correct |
101 ms |
233404 KB |
Output is correct |
12 |
Correct |
109 ms |
233348 KB |
Output is correct |
13 |
Correct |
101 ms |
233448 KB |
Output is correct |
14 |
Correct |
294 ms |
319196 KB |
Output is correct |
15 |
Correct |
306 ms |
324972 KB |
Output is correct |
16 |
Correct |
282 ms |
309444 KB |
Output is correct |
17 |
Correct |
386 ms |
310732 KB |
Output is correct |
18 |
Correct |
298 ms |
323424 KB |
Output is correct |
19 |
Correct |
136 ms |
233616 KB |
Output is correct |
20 |
Correct |
123 ms |
233980 KB |
Output is correct |
21 |
Correct |
115 ms |
233796 KB |
Output is correct |
22 |
Correct |
118 ms |
235312 KB |
Output is correct |
23 |
Correct |
204 ms |
253732 KB |
Output is correct |
24 |
Correct |
105 ms |
233388 KB |
Output is correct |
25 |
Correct |
105 ms |
233436 KB |
Output is correct |
26 |
Correct |
110 ms |
233392 KB |
Output is correct |
27 |
Correct |
507 ms |
404828 KB |
Output is correct |
28 |
Correct |
534 ms |
416488 KB |
Output is correct |
29 |
Correct |
467 ms |
385452 KB |
Output is correct |
30 |
Correct |
478 ms |
387908 KB |
Output is correct |
31 |
Correct |
526 ms |
413508 KB |
Output is correct |
32 |
Correct |
115 ms |
233704 KB |
Output is correct |
33 |
Correct |
124 ms |
234540 KB |
Output is correct |
34 |
Correct |
121 ms |
234048 KB |
Output is correct |
35 |
Correct |
123 ms |
237224 KB |
Output is correct |
36 |
Correct |
233 ms |
273988 KB |
Output is correct |
37 |
Correct |
124 ms |
233312 KB |
Output is correct |
38 |
Correct |
104 ms |
233428 KB |
Output is correct |
39 |
Correct |
103 ms |
233540 KB |
Output is correct |
40 |
Correct |
146 ms |
243516 KB |
Output is correct |
41 |
Correct |
158 ms |
243772 KB |
Output is correct |
42 |
Correct |
128 ms |
241348 KB |
Output is correct |
43 |
Correct |
122 ms |
239800 KB |
Output is correct |
44 |
Correct |
144 ms |
244576 KB |
Output is correct |
45 |
Correct |
101 ms |
233420 KB |
Output is correct |
46 |
Correct |
113 ms |
235976 KB |
Output is correct |
47 |
Correct |
113 ms |
234264 KB |
Output is correct |
48 |
Correct |
135 ms |
234024 KB |
Output is correct |
49 |
Correct |
121 ms |
233368 KB |
Output is correct |
50 |
Correct |
104 ms |
233412 KB |
Output is correct |
51 |
Correct |
103 ms |
233344 KB |
Output is correct |
52 |
Correct |
149 ms |
240720 KB |
Output is correct |
53 |
Correct |
205 ms |
255008 KB |
Output is correct |
54 |
Correct |
230 ms |
254312 KB |
Output is correct |
55 |
Correct |
197 ms |
251144 KB |
Output is correct |
56 |
Correct |
174 ms |
250928 KB |
Output is correct |
57 |
Correct |
198 ms |
255108 KB |
Output is correct |
58 |
Correct |
122 ms |
233572 KB |
Output is correct |
59 |
Correct |
111 ms |
235452 KB |
Output is correct |
60 |
Correct |
108 ms |
234348 KB |
Output is correct |
61 |
Correct |
112 ms |
235284 KB |
Output is correct |
62 |
Correct |
154 ms |
239128 KB |
Output is correct |
63 |
Correct |
107 ms |
233484 KB |
Output is correct |
64 |
Correct |
104 ms |
233412 KB |
Output is correct |
65 |
Correct |
124 ms |
237864 KB |
Output is correct |
66 |
Runtime error |
1693 ms |
524292 KB |
Execution killed with signal 9 |
67 |
Halted |
0 ms |
0 KB |
- |