# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
511145 |
2022-01-15T09:16:50 Z |
Mazaalai |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
125892 KB |
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LLA(x) x.rbegin(),x.rend()
#define print(x) for(auto el:x)cout<<el<<' ';cout<<"\n";
#define printPII(x) for(auto [a,b]:x)cout<<a<<","<<b<<' ';cout<<'\n';
using namespace std;
using ll = long long;
using PII = pair <ll, ll>;
ll n, k, onePick = 1;
bool impossible;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n >> k;
vector <vector <ll> > ans;
set <PII> bfs;
ll sum = 0, val, id, dbg = 0;
for (int i = 1; i <= n; i++) {
ll x; cin >> x;
sum += x;
bfs.insert({x, i});
}
bfs.insert({0, 0});
ll packs = sum / k;
if (sum % k != 0 || bfs.rbegin()->ff > packs) {
cout << "-1\n";
return 0;
}
while(packs > 0) {
vector <PII> add;
for (int i = 0; i < k; i++) {
auto it = --bfs.end();
tie(val, id) = *it;
bfs.erase(it);
add.pb({val, id});
}
ll pick = min(add.back().ff, packs-((--bfs.end())->ff));
packs -= pick;
vector <ll> cur(1, pick);
for (int i = 0; i < k; i++) {
tie(val, id) = add.back();
add.pop_back();
val -= pick;
cur.pb(id);
bfs.insert({val, id});
}
ans.pb(cur);
}
cout << ans.size() << '\n';
for (auto el : ans) {print(el);}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:22:23: warning: unused variable 'dbg' [-Wunused-variable]
22 | ll sum = 0, val, id, dbg = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
316 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
316 KB |
n=2 |
7 |
Correct |
0 ms |
312 KB |
n=5 |
8 |
Correct |
1 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
35 ms |
5604 KB |
n=50000 |
12 |
Correct |
33 ms |
5244 KB |
n=50000 |
13 |
Correct |
0 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
316 KB |
n=2 |
7 |
Correct |
0 ms |
312 KB |
n=5 |
8 |
Correct |
1 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
35 ms |
5604 KB |
n=50000 |
12 |
Correct |
33 ms |
5244 KB |
n=50000 |
13 |
Correct |
0 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
17 |
Correct |
1 ms |
332 KB |
n=989 |
18 |
Correct |
1 ms |
332 KB |
n=563 |
19 |
Correct |
1 ms |
332 KB |
n=592 |
20 |
Correct |
1 ms |
332 KB |
n=938 |
21 |
Correct |
1 ms |
312 KB |
n=747 |
22 |
Correct |
1 ms |
332 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
947 ms |
104724 KB |
n=1000000 |
2 |
Correct |
557 ms |
70544 KB |
n=666666 |
3 |
Correct |
312 ms |
40976 KB |
n=400000 |
4 |
Correct |
200 ms |
28788 KB |
n=285714 |
5 |
Correct |
13 ms |
2100 KB |
n=20000 |
6 |
Correct |
120 ms |
17784 KB |
n=181818 |
7 |
Correct |
6 ms |
1136 KB |
n=10000 |
8 |
Correct |
5 ms |
972 KB |
n=6666 |
9 |
Correct |
3 ms |
568 KB |
n=4000 |
10 |
Correct |
6 ms |
716 KB |
n=2857 |
11 |
Correct |
2 ms |
456 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
204 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
316 KB |
n=2 |
7 |
Correct |
0 ms |
312 KB |
n=5 |
8 |
Correct |
1 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
204 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
35 ms |
5604 KB |
n=50000 |
12 |
Correct |
33 ms |
5244 KB |
n=50000 |
13 |
Correct |
0 ms |
204 KB |
n=10 |
14 |
Correct |
1 ms |
332 KB |
n=685 |
15 |
Correct |
1 ms |
332 KB |
n=623 |
16 |
Correct |
1 ms |
332 KB |
n=973 |
17 |
Correct |
1 ms |
332 KB |
n=989 |
18 |
Correct |
1 ms |
332 KB |
n=563 |
19 |
Correct |
1 ms |
332 KB |
n=592 |
20 |
Correct |
1 ms |
332 KB |
n=938 |
21 |
Correct |
1 ms |
312 KB |
n=747 |
22 |
Correct |
1 ms |
332 KB |
n=991 |
23 |
Correct |
947 ms |
104724 KB |
n=1000000 |
24 |
Correct |
557 ms |
70544 KB |
n=666666 |
25 |
Correct |
312 ms |
40976 KB |
n=400000 |
26 |
Correct |
200 ms |
28788 KB |
n=285714 |
27 |
Correct |
13 ms |
2100 KB |
n=20000 |
28 |
Correct |
120 ms |
17784 KB |
n=181818 |
29 |
Correct |
6 ms |
1136 KB |
n=10000 |
30 |
Correct |
5 ms |
972 KB |
n=6666 |
31 |
Correct |
3 ms |
568 KB |
n=4000 |
32 |
Correct |
6 ms |
716 KB |
n=2857 |
33 |
Correct |
2 ms |
456 KB |
n=2000 |
34 |
Correct |
22 ms |
3220 KB |
n=23514 |
35 |
Correct |
22 ms |
3208 KB |
n=23514 |
36 |
Correct |
1 ms |
308 KB |
n=940 |
37 |
Correct |
0 ms |
312 KB |
n=2 |
38 |
Correct |
75 ms |
9452 KB |
n=100000 |
39 |
Correct |
69 ms |
9336 KB |
n=100000 |
40 |
Correct |
1 ms |
204 KB |
n=10 |
41 |
Correct |
1 ms |
388 KB |
n=100 |
42 |
Correct |
5 ms |
460 KB |
n=1000 |
43 |
Correct |
1073 ms |
125892 KB |
n=1000000 |
44 |
Execution timed out |
2077 ms |
103084 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |