#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 2e3 + 50;
const ll Mod = 1e9 + 7;
ll n, k, w[N], d[N];
vector<pll> vec;
vector<ll> best[N], help[N];
int main(){
fast_io;
cin >> n >> k;
for(ll i = 1; i <= n; i++){
ll ww, dd;
cin >> ww >> dd;
vec.pb({dd, ww});
}
sort(all(vec));
for(ll i = 0; i < n; i++){
w[i+1] = vec[i].S; d[i+1] = vec[i].F;
}
best[0].pb(0);
for(ll i = 1; i <= n; i++){
for(ll j = 0; j < d[i]; j++){
for(ll x: best[j]) help[j+1].pb(x+w[i]);
}
for(ll j = 0; j <= n; j++){
for(ll x: help[j]) best[j].pb(x);
help[j].clear(); sort(all(best[j]));
while(best[j].size() > k) best[j].pop_back();
}
}
ll cnt = 0, cur = n, cur2 = 0;
while(cnt + best[cur].size() <= k){
for(ll x: best[cur]) cout << cur << sep << x << endl;
cnt += best[cur].size(); cur--;
}
k -= cnt;
while(k--) cout << cur << sep << best[cur][cur2++] << endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:58:34: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
58 | while(best[j].size() > k) best[j].pop_back();
| ~~~~~~~~~~~~~~~^~~
Main.cpp:63:34: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
63 | while(cnt + best[cur].size() <= k){
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
736 KB |
Output is correct |
2 |
Correct |
44 ms |
604 KB |
Output is correct |
3 |
Correct |
26 ms |
852 KB |
Output is correct |
4 |
Correct |
23 ms |
600 KB |
Output is correct |
5 |
Correct |
29 ms |
752 KB |
Output is correct |
6 |
Correct |
9 ms |
676 KB |
Output is correct |
7 |
Correct |
10 ms |
680 KB |
Output is correct |
8 |
Correct |
11 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
600 KB |
Output is correct |
10 |
Correct |
16 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
736 KB |
Output is correct |
2 |
Correct |
44 ms |
604 KB |
Output is correct |
3 |
Correct |
26 ms |
852 KB |
Output is correct |
4 |
Correct |
23 ms |
600 KB |
Output is correct |
5 |
Correct |
29 ms |
752 KB |
Output is correct |
6 |
Correct |
9 ms |
676 KB |
Output is correct |
7 |
Correct |
10 ms |
680 KB |
Output is correct |
8 |
Correct |
11 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
600 KB |
Output is correct |
10 |
Correct |
16 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
556 KB |
Output is correct |
14 |
Correct |
27 ms |
604 KB |
Output is correct |
15 |
Correct |
29 ms |
752 KB |
Output is correct |
16 |
Correct |
42 ms |
716 KB |
Output is correct |
17 |
Correct |
25 ms |
604 KB |
Output is correct |
18 |
Correct |
39 ms |
852 KB |
Output is correct |
19 |
Correct |
8 ms |
680 KB |
Output is correct |
20 |
Correct |
9 ms |
604 KB |
Output is correct |
21 |
Correct |
8 ms |
604 KB |
Output is correct |
22 |
Correct |
13 ms |
680 KB |
Output is correct |
23 |
Correct |
13 ms |
692 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
600 KB |
Output is correct |
2 |
Correct |
37 ms |
604 KB |
Output is correct |
3 |
Correct |
32 ms |
600 KB |
Output is correct |
4 |
Correct |
33 ms |
780 KB |
Output is correct |
5 |
Correct |
36 ms |
776 KB |
Output is correct |
6 |
Correct |
8 ms |
600 KB |
Output is correct |
7 |
Correct |
10 ms |
604 KB |
Output is correct |
8 |
Correct |
8 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
604 KB |
Output is correct |
10 |
Correct |
14 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1112 KB |
Output is correct |
2 |
Correct |
8 ms |
1220 KB |
Output is correct |
3 |
Correct |
7 ms |
1116 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
11 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
1072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
604 KB |
Output is correct |
2 |
Correct |
8 ms |
844 KB |
Output is correct |
3 |
Correct |
7 ms |
600 KB |
Output is correct |
4 |
Correct |
7 ms |
604 KB |
Output is correct |
5 |
Correct |
9 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
736 KB |
Output is correct |
2 |
Correct |
44 ms |
604 KB |
Output is correct |
3 |
Correct |
26 ms |
852 KB |
Output is correct |
4 |
Correct |
23 ms |
600 KB |
Output is correct |
5 |
Correct |
29 ms |
752 KB |
Output is correct |
6 |
Correct |
9 ms |
676 KB |
Output is correct |
7 |
Correct |
10 ms |
680 KB |
Output is correct |
8 |
Correct |
11 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
600 KB |
Output is correct |
10 |
Correct |
16 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
556 KB |
Output is correct |
14 |
Correct |
27 ms |
604 KB |
Output is correct |
15 |
Correct |
29 ms |
752 KB |
Output is correct |
16 |
Correct |
42 ms |
716 KB |
Output is correct |
17 |
Correct |
25 ms |
604 KB |
Output is correct |
18 |
Correct |
39 ms |
852 KB |
Output is correct |
19 |
Correct |
8 ms |
680 KB |
Output is correct |
20 |
Correct |
9 ms |
604 KB |
Output is correct |
21 |
Correct |
8 ms |
604 KB |
Output is correct |
22 |
Correct |
13 ms |
680 KB |
Output is correct |
23 |
Correct |
13 ms |
692 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
34 ms |
600 KB |
Output is correct |
28 |
Correct |
37 ms |
604 KB |
Output is correct |
29 |
Correct |
32 ms |
600 KB |
Output is correct |
30 |
Correct |
33 ms |
780 KB |
Output is correct |
31 |
Correct |
36 ms |
776 KB |
Output is correct |
32 |
Correct |
8 ms |
600 KB |
Output is correct |
33 |
Correct |
10 ms |
604 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
8 ms |
604 KB |
Output is correct |
36 |
Correct |
14 ms |
604 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1112 KB |
Output is correct |
41 |
Correct |
8 ms |
1220 KB |
Output is correct |
42 |
Correct |
7 ms |
1116 KB |
Output is correct |
43 |
Correct |
4 ms |
856 KB |
Output is correct |
44 |
Correct |
11 ms |
1116 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
560 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
2 ms |
600 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
344 KB |
Output is correct |
52 |
Correct |
5 ms |
1072 KB |
Output is correct |
53 |
Correct |
9 ms |
604 KB |
Output is correct |
54 |
Correct |
8 ms |
844 KB |
Output is correct |
55 |
Correct |
7 ms |
600 KB |
Output is correct |
56 |
Correct |
7 ms |
604 KB |
Output is correct |
57 |
Correct |
9 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
2 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
2 ms |
604 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
2 ms |
604 KB |
Output is correct |
66 |
Execution timed out |
5032 ms |
22488 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |