#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;
vector <pii> arr;
vector <Node> ops;
bool flag = true;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
arr.resize(N);
for (int i = 0; i < N; i++) {
auto &[v, id] = arr[i];
cin >> v;
id = i + 1;
}
while (flag) {
sort(All(arr), [](const pii x, const pii y){
return x.ff > y.ff;
});
if (!arr[0].ff) {
break;
} else if (!arr[K-1].ff) {
flag = false;
break;
}
int sum = 0, mmax = (K < N ? arr[K].ff : 0);
for (int i = 0; i < N; i++)
sum += arr[i].ff;
int p = min(arr[K-1].ff, (sum - (mmax * K)) / K);
if (p <= 0) {
flag = false;
}
ops.pb(Node(p));
for (int i = 0; i < K; i++) {
arr[i].ff -= p;
ops[ops.size()-1].I.pb(arr[i].ss);
}
}
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:32:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
32 | auto &[v, id] = arr[i];
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 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 |
1 ms |
364 KB |
n=14 |
10 |
Correct |
0 ms |
364 KB |
n=11 |
11 |
Execution timed out |
2075 ms |
1140 KB |
Time limit exceeded |
12 |
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 |
1 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 |
1 ms |
364 KB |
n=14 |
10 |
Correct |
0 ms |
364 KB |
n=11 |
11 |
Execution timed out |
2075 ms |
1140 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
8172 KB |
Jury has the answer but participant has not |
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 |
1 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 |
1 ms |
364 KB |
n=14 |
10 |
Correct |
0 ms |
364 KB |
n=11 |
11 |
Execution timed out |
2075 ms |
1140 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |