# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
651942 |
2022-10-20T16:29:27 Z |
vovik |
Gift (IZhO18_nicegift) |
C++17 |
|
1120 ms |
108400 KB |
//I wrote this code 4 u today
#include <bits/stdc++.h>
#define vc vector
#define nd node*
#define pnd pair<nd, nd>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vc<pll> vpll;
typedef vc<vll> vvll;
typedef vc<vpll> vvpll;
template<const ll MOD>
struct mod_mul : std::multiplies<const ll> {
ll operator()(const ll a, const ll b) {
return (a * b) % MOD;
}
};
template<typename T>
inline void sort(T &a) {
sort(a.begin(), a.end());
}
template<typename T>
inline void unique(T &a) {
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template<typename T>
inline void reverse(T &a) {
reverse(a.begin(), a.end());
}
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
#define int ll
int32_t main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vc<ll> a(n);
ll sm = 0, mx = 0;
for (auto &i : a) cin >> i, sm += i, mx = max(mx, i);
if (sm % k || mx > sm / k) return cout << "-1\n", 0;
priority_queue<pair<int, int>> alive;
for (int i = 0; i < n; ++i) if (a[i]) alive.emplace(a[i], i);
vc<vc<int>> ans;
while (!alive.empty()) {
vc<int> inds(k);
for (int i = k - 1; i >= 0; --i) inds[i] = alive.top().second, alive.pop();
if (!a[inds.back()]) break;
int d = min(sm / k - (alive.empty() ? 0 : alive.top().first), a[inds[0]]);
ans.push_back({d});
for (auto i : inds) ans.back().push_back(i + 1), a[i] -= d, alive.emplace(a[i], i);
sm -= k * d;
}
cout << ans.size() << '\n';
for (auto v : ans) {
for (auto &i : v) cout << i << ' ';
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
n=4 |
2 |
Correct |
1 ms |
316 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
320 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
n=4 |
2 |
Correct |
1 ms |
316 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
320 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
340 KB |
n=14 |
10 |
Correct |
1 ms |
316 KB |
n=11 |
11 |
Correct |
23 ms |
4124 KB |
n=50000 |
12 |
Correct |
23 ms |
3656 KB |
n=50000 |
13 |
Correct |
1 ms |
316 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
n=4 |
2 |
Correct |
1 ms |
316 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
320 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
340 KB |
n=14 |
10 |
Correct |
1 ms |
316 KB |
n=11 |
11 |
Correct |
23 ms |
4124 KB |
n=50000 |
12 |
Correct |
23 ms |
3656 KB |
n=50000 |
13 |
Correct |
1 ms |
316 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
316 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
526 ms |
87104 KB |
n=1000000 |
2 |
Correct |
300 ms |
48636 KB |
n=666666 |
3 |
Correct |
165 ms |
27664 KB |
n=400000 |
4 |
Correct |
116 ms |
17756 KB |
n=285714 |
5 |
Correct |
7 ms |
1368 KB |
n=20000 |
6 |
Correct |
70 ms |
11500 KB |
n=181818 |
7 |
Correct |
4 ms |
852 KB |
n=10000 |
8 |
Correct |
4 ms |
724 KB |
n=6666 |
9 |
Correct |
2 ms |
540 KB |
n=4000 |
10 |
Correct |
4 ms |
724 KB |
n=2857 |
11 |
Correct |
1 ms |
340 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
n=4 |
2 |
Correct |
1 ms |
316 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
320 KB |
n=4 |
6 |
Correct |
1 ms |
212 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
340 KB |
n=14 |
10 |
Correct |
1 ms |
316 KB |
n=11 |
11 |
Correct |
23 ms |
4124 KB |
n=50000 |
12 |
Correct |
23 ms |
3656 KB |
n=50000 |
13 |
Correct |
1 ms |
316 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
1 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
316 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
23 |
Correct |
526 ms |
87104 KB |
n=1000000 |
24 |
Correct |
300 ms |
48636 KB |
n=666666 |
25 |
Correct |
165 ms |
27664 KB |
n=400000 |
26 |
Correct |
116 ms |
17756 KB |
n=285714 |
27 |
Correct |
7 ms |
1368 KB |
n=20000 |
28 |
Correct |
70 ms |
11500 KB |
n=181818 |
29 |
Correct |
4 ms |
852 KB |
n=10000 |
30 |
Correct |
4 ms |
724 KB |
n=6666 |
31 |
Correct |
2 ms |
540 KB |
n=4000 |
32 |
Correct |
4 ms |
724 KB |
n=2857 |
33 |
Correct |
1 ms |
340 KB |
n=2000 |
34 |
Correct |
15 ms |
2508 KB |
n=23514 |
35 |
Correct |
15 ms |
2468 KB |
n=23514 |
36 |
Correct |
1 ms |
320 KB |
n=940 |
37 |
Correct |
1 ms |
212 KB |
n=2 |
38 |
Correct |
44 ms |
5784 KB |
n=100000 |
39 |
Correct |
39 ms |
5896 KB |
n=100000 |
40 |
Correct |
1 ms |
324 KB |
n=10 |
41 |
Correct |
1 ms |
324 KB |
n=100 |
42 |
Correct |
3 ms |
468 KB |
n=1000 |
43 |
Correct |
623 ms |
98464 KB |
n=1000000 |
44 |
Correct |
1120 ms |
108400 KB |
n=1000000 |
45 |
Correct |
710 ms |
63644 KB |
n=666666 |
46 |
Correct |
372 ms |
38088 KB |
n=400000 |
47 |
Correct |
13 ms |
1108 KB |
n=2336 |
48 |
Correct |
589 ms |
54688 KB |
n=285714 |
49 |
Correct |
530 ms |
50912 KB |
n=181818 |
50 |
Correct |
28 ms |
3140 KB |
n=40000 |
51 |
Correct |
14 ms |
1644 KB |
n=20000 |
52 |
Correct |
9 ms |
1060 KB |
n=10000 |
53 |
Correct |
52 ms |
6064 KB |
n=6666 |
54 |
Correct |
5 ms |
596 KB |
n=4000 |
55 |
Correct |
200 ms |
20772 KB |
n=2857 |
56 |
Correct |
3 ms |
468 KB |
n=2000 |