#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define fi first
#define se second
const int N = 200200;
using namespace std;
int n;
int k;
long long a[N];
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> k;
set < pair < long long, int > > s;
long long S = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
s.insert({a[i], i});
S += a[i];
}
if(1ll * (--s.end())->fi > S / k || S % k){
cout << -1 << "\n";
return 0;
}
vector < long long > qu;
vector < vector < int > > res;
vector < int > v;
while(s.size() > 0){
v.clear();
for(int i = 0; i < k; i++){
v.push_back((--s.end())->se);
s.erase(--s.end());
}
long long rem = 0;
if(!s.empty()){
rem = (--s.end())->fi;
}
long long l = 1, r = a[v.back()];
while(l < r){
long long m = (l + r) / 2 + 1;
if(max(rem, a[v[0]] - m) > (S - m * k) / k){
r = m - 1;
} else{
l = m;
}
}
res.push_back(v);
qu.push_back(l);
for(int i: v){
a[i] -= l;
if(!a[i]){
continue;
}
s.insert({a[i], i});
}
}
cout << qu.size() << "\n";
for(int i = 0; i < qu.size(); i++){
cout << qu[i];
for(int x: res[i]){
cout << " " << x;
}
cout << "\n";
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:71:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < qu.size(); i++){
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
380 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
380 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
3 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
380 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
3 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
118 ms |
14404 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
380 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
3 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |