# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
511084 |
2022-01-15T05:44:25 Z |
Mazaalai |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
211412 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 PII = pair <int, int>;
using ll = long long;
int n, k;
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 <int> > ans;
set <PII> bfs;
ll sum = 0;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
sum += x;
bfs.insert({x, i});
}
while(!impossible && sum > 0) {
vector <int> pick(1, 1);
vector <PII> add;
for (int i = 0; i < k; i++) {
auto it = --bfs.end();
PII cur = *it;
bfs.erase(it);
pick.pb(cur.ss);
cur.ff--;
sum--;
if (cur.ff < 0) {
impossible = 1;
break;
}
add.pb(cur);
}
ans.pb(pick);
for (auto el : add) bfs.insert(el);
}
// int dbg = 0;
if (impossible) {
cout << "-1\n";
return 0;
}
cout << ans.size() << '\n';
for (auto el : ans) {
print(el);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
1 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
312 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
1 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
312 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
3 ms |
972 KB |
n=8 |
9 |
Correct |
9 ms |
1160 KB |
n=14 |
10 |
Correct |
6 ms |
972 KB |
n=11 |
11 |
Correct |
48 ms |
6116 KB |
n=50000 |
12 |
Correct |
64 ms |
6096 KB |
n=50000 |
13 |
Correct |
46 ms |
3396 KB |
n=10 |
14 |
Correct |
31 ms |
2976 KB |
n=685 |
15 |
Correct |
34 ms |
3400 KB |
n=623 |
16 |
Correct |
18 ms |
1924 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
1 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
312 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
3 ms |
972 KB |
n=8 |
9 |
Correct |
9 ms |
1160 KB |
n=14 |
10 |
Correct |
6 ms |
972 KB |
n=11 |
11 |
Correct |
48 ms |
6116 KB |
n=50000 |
12 |
Correct |
64 ms |
6096 KB |
n=50000 |
13 |
Correct |
46 ms |
3396 KB |
n=10 |
14 |
Correct |
31 ms |
2976 KB |
n=685 |
15 |
Correct |
34 ms |
3400 KB |
n=623 |
16 |
Correct |
18 ms |
1924 KB |
n=973 |
17 |
Correct |
33 ms |
2496 KB |
n=989 |
18 |
Correct |
13 ms |
968 KB |
n=563 |
19 |
Correct |
25 ms |
1292 KB |
n=592 |
20 |
Correct |
25 ms |
1256 KB |
n=938 |
21 |
Correct |
29 ms |
1156 KB |
n=747 |
22 |
Correct |
21 ms |
1208 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2076 ms |
211412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
1 ms |
204 KB |
n=4 |
5 |
Correct |
1 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
312 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
3 ms |
972 KB |
n=8 |
9 |
Correct |
9 ms |
1160 KB |
n=14 |
10 |
Correct |
6 ms |
972 KB |
n=11 |
11 |
Correct |
48 ms |
6116 KB |
n=50000 |
12 |
Correct |
64 ms |
6096 KB |
n=50000 |
13 |
Correct |
46 ms |
3396 KB |
n=10 |
14 |
Correct |
31 ms |
2976 KB |
n=685 |
15 |
Correct |
34 ms |
3400 KB |
n=623 |
16 |
Correct |
18 ms |
1924 KB |
n=973 |
17 |
Correct |
33 ms |
2496 KB |
n=989 |
18 |
Correct |
13 ms |
968 KB |
n=563 |
19 |
Correct |
25 ms |
1292 KB |
n=592 |
20 |
Correct |
25 ms |
1256 KB |
n=938 |
21 |
Correct |
29 ms |
1156 KB |
n=747 |
22 |
Correct |
21 ms |
1208 KB |
n=991 |
23 |
Execution timed out |
2076 ms |
211412 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |