# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
651943 |
2022-10-20T16:29:41 Z |
vovik |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
138868 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;
set<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.rbegin()->second, alive.erase(prev(alive.end()));
if (!a[inds.back()]) break;
int d = min(sm / k - (alive.empty() ? 0 : alive.rbegin()->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 |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
320 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
41 ms |
6412 KB |
n=50000 |
12 |
Correct |
36 ms |
5992 KB |
n=50000 |
13 |
Correct |
1 ms |
320 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 |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
320 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
41 ms |
6412 KB |
n=50000 |
12 |
Correct |
36 ms |
5992 KB |
n=50000 |
13 |
Correct |
1 ms |
320 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 |
2 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
320 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
320 KB |
n=747 |
22 |
Correct |
1 ms |
316 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
933 ms |
120636 KB |
n=1000000 |
2 |
Correct |
556 ms |
71020 KB |
n=666666 |
3 |
Correct |
346 ms |
40716 KB |
n=400000 |
4 |
Correct |
230 ms |
27256 KB |
n=285714 |
5 |
Correct |
13 ms |
2132 KB |
n=20000 |
6 |
Correct |
135 ms |
17444 KB |
n=181818 |
7 |
Correct |
7 ms |
1236 KB |
n=10000 |
8 |
Correct |
5 ms |
980 KB |
n=6666 |
9 |
Correct |
3 ms |
592 KB |
n=4000 |
10 |
Correct |
5 ms |
848 KB |
n=2857 |
11 |
Correct |
2 ms |
468 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n=4 |
2 |
Correct |
1 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
212 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
7 |
Correct |
1 ms |
212 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
320 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
41 ms |
6412 KB |
n=50000 |
12 |
Correct |
36 ms |
5992 KB |
n=50000 |
13 |
Correct |
1 ms |
320 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 |
2 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
320 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
320 KB |
n=747 |
22 |
Correct |
1 ms |
316 KB |
n=991 |
23 |
Correct |
933 ms |
120636 KB |
n=1000000 |
24 |
Correct |
556 ms |
71020 KB |
n=666666 |
25 |
Correct |
346 ms |
40716 KB |
n=400000 |
26 |
Correct |
230 ms |
27256 KB |
n=285714 |
27 |
Correct |
13 ms |
2132 KB |
n=20000 |
28 |
Correct |
135 ms |
17444 KB |
n=181818 |
29 |
Correct |
7 ms |
1236 KB |
n=10000 |
30 |
Correct |
5 ms |
980 KB |
n=6666 |
31 |
Correct |
3 ms |
592 KB |
n=4000 |
32 |
Correct |
5 ms |
848 KB |
n=2857 |
33 |
Correct |
2 ms |
468 KB |
n=2000 |
34 |
Correct |
34 ms |
3564 KB |
n=23514 |
35 |
Correct |
29 ms |
3480 KB |
n=23514 |
36 |
Correct |
2 ms |
468 KB |
n=940 |
37 |
Correct |
1 ms |
320 KB |
n=2 |
38 |
Correct |
95 ms |
10180 KB |
n=100000 |
39 |
Correct |
83 ms |
10128 KB |
n=100000 |
40 |
Correct |
1 ms |
316 KB |
n=10 |
41 |
Correct |
1 ms |
320 KB |
n=100 |
42 |
Correct |
5 ms |
584 KB |
n=1000 |
43 |
Correct |
1146 ms |
138868 KB |
n=1000000 |
44 |
Execution timed out |
2062 ms |
97184 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |