#include <bits/stdc++.h>
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
struct Node {
int X;
vector <int> I;
Node(int x) {
X = x;
}
};
const int MAXN = 1000000;
int N, K;
int v;
vector <Node> ops;
bool flag = true;
set <pii> now;
int sum;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> v;
sum += v;
now.insert(pii(v, i+1));
}
while (now.size()) {
if (now.size() < K) {
flag = false;
break;
}
auto it = prev(now.end());
ops.pb(1);
vector <pii> tmp;
int x = 0;
// debug(now.size());
for (int i = 0; i < K; i++) {
// debug(it->ff, it->ss);
ops[ops.size()-1].I.pb(it->ss);
sum -= it->ff;
tmp.pb(*it);
if (i+1 < K) {
it = prev(now.erase(it));
} else {
now.erase(it);
if (!now.size()) {
x = it->ff;
} else {
x = max(it->ff - prev(now.end())->ff + 1, (prev(now.end())->ff - sum) / K);
}
}
}
ops[ops.size()-1].X = x;
for (pii i : tmp) {
if (i.ff-x)
now.insert(pii(i.ff-x, i.ss));
sum += i.ff-x;
}
}
if (flag) {
cout << ops.size() << '\n';
for (Node now : ops) {
cout << now.X;
for (int i : now.I) cout << ' ' << i;
cout << '\n';
}
} else {
cout << -1 << '\n';
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:38:18: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
38 | if (now.size() < K) {
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
6 ms |
1132 KB |
n=14 |
10 |
Correct |
4 ms |
748 KB |
n=11 |
11 |
Correct |
35 ms |
4192 KB |
n=50000 |
12 |
Correct |
44 ms |
5216 KB |
n=50000 |
13 |
Correct |
16 ms |
2020 KB |
n=10 |
14 |
Correct |
33 ms |
3424 KB |
n=685 |
15 |
Correct |
36 ms |
3680 KB |
n=623 |
16 |
Correct |
21 ms |
2272 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
6 ms |
1132 KB |
n=14 |
10 |
Correct |
4 ms |
748 KB |
n=11 |
11 |
Correct |
35 ms |
4192 KB |
n=50000 |
12 |
Correct |
44 ms |
5216 KB |
n=50000 |
13 |
Correct |
16 ms |
2020 KB |
n=10 |
14 |
Correct |
33 ms |
3424 KB |
n=685 |
15 |
Correct |
36 ms |
3680 KB |
n=623 |
16 |
Correct |
21 ms |
2272 KB |
n=973 |
17 |
Correct |
37 ms |
2872 KB |
n=989 |
18 |
Correct |
16 ms |
1128 KB |
n=563 |
19 |
Correct |
26 ms |
1564 KB |
n=592 |
20 |
Correct |
26 ms |
1512 KB |
n=938 |
21 |
Correct |
20 ms |
1384 KB |
n=747 |
22 |
Correct |
23 ms |
1384 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2080 ms |
244628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
6 ms |
1132 KB |
n=14 |
10 |
Correct |
4 ms |
748 KB |
n=11 |
11 |
Correct |
35 ms |
4192 KB |
n=50000 |
12 |
Correct |
44 ms |
5216 KB |
n=50000 |
13 |
Correct |
16 ms |
2020 KB |
n=10 |
14 |
Correct |
33 ms |
3424 KB |
n=685 |
15 |
Correct |
36 ms |
3680 KB |
n=623 |
16 |
Correct |
21 ms |
2272 KB |
n=973 |
17 |
Correct |
37 ms |
2872 KB |
n=989 |
18 |
Correct |
16 ms |
1128 KB |
n=563 |
19 |
Correct |
26 ms |
1564 KB |
n=592 |
20 |
Correct |
26 ms |
1512 KB |
n=938 |
21 |
Correct |
20 ms |
1384 KB |
n=747 |
22 |
Correct |
23 ms |
1384 KB |
n=991 |
23 |
Execution timed out |
2080 ms |
244628 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |