#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const ll N = 2e6 + 5, INF = 2e18 + 5;
ll n, k;
pair < ll, ll > P[N];
ll nn;
vector < ll > V[N], v;
main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for (ll i = 1; i <= n; i++){
cin>>P[i].F;
P[i].S = i;
}
sort (P + 1, P + n + 1);
reverse (P + 1, P + n + 1);
while (P[k].F > 0){
ll I1 = k, I2 = k;
for (ll i = 20; i >= 0; i--){
if (I1 - (1<<i) <= 0)
continue;
if (P[I1 - (1<<i)].F == P[k].F)
I1 -= (1<<i);
}
for (ll i = 20; i >= 0; i--){
if (I2 + (1<<i) > n)
continue;
if (P[I2 + (1<<i)].F == P[k].F)
I2 += (1<<i);
}
ll x = min (max (1ll, P[I1 - 1].F - P[I1].F), P[I2].F - P[I2 + 1].F);
v.clear();
v.pb(x);
for (ll i = 1; i < I1; i++){
v.pb (P[i].S);
P[i].F-=x;
}
for (ll i = I2; (ll)v.size() <= k; i--){
v.pb (P[i].S);
P[i].F-=x;
}
V[++nn] = v;
}
if (P[1].F > 0){
cout<<-1<<endl;
return 0;
}
cout<<nn<<endl;
for (ll i = 1; i <= nn; i++){
cout<<V[i][0]<<" ";
for (ll j = 1; j <= k; j++)
cout<<V[i][j]<<" ";
cout<<endl;
}
return 0;
}
Compilation message
nicegift.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
n=4 |
2 |
Correct |
43 ms |
47484 KB |
n=3 |
3 |
Correct |
43 ms |
47484 KB |
n=3 |
4 |
Correct |
42 ms |
47484 KB |
n=4 |
5 |
Correct |
43 ms |
47484 KB |
n=4 |
6 |
Correct |
43 ms |
47484 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
n=4 |
2 |
Correct |
43 ms |
47484 KB |
n=3 |
3 |
Correct |
43 ms |
47484 KB |
n=3 |
4 |
Correct |
42 ms |
47484 KB |
n=4 |
5 |
Correct |
43 ms |
47484 KB |
n=4 |
6 |
Correct |
43 ms |
47484 KB |
n=2 |
7 |
Correct |
44 ms |
47492 KB |
n=5 |
8 |
Correct |
38 ms |
47492 KB |
n=8 |
9 |
Correct |
50 ms |
47636 KB |
n=14 |
10 |
Correct |
46 ms |
47648 KB |
n=11 |
11 |
Correct |
103 ms |
49736 KB |
n=50000 |
12 |
Correct |
118 ms |
50192 KB |
n=50000 |
13 |
Correct |
95 ms |
50192 KB |
n=10 |
14 |
Correct |
104 ms |
50192 KB |
n=685 |
15 |
Correct |
109 ms |
50192 KB |
n=623 |
16 |
Correct |
77 ms |
50192 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
n=4 |
2 |
Correct |
43 ms |
47484 KB |
n=3 |
3 |
Correct |
43 ms |
47484 KB |
n=3 |
4 |
Correct |
42 ms |
47484 KB |
n=4 |
5 |
Correct |
43 ms |
47484 KB |
n=4 |
6 |
Correct |
43 ms |
47484 KB |
n=2 |
7 |
Correct |
44 ms |
47492 KB |
n=5 |
8 |
Correct |
38 ms |
47492 KB |
n=8 |
9 |
Correct |
50 ms |
47636 KB |
n=14 |
10 |
Correct |
46 ms |
47648 KB |
n=11 |
11 |
Correct |
103 ms |
49736 KB |
n=50000 |
12 |
Correct |
118 ms |
50192 KB |
n=50000 |
13 |
Correct |
95 ms |
50192 KB |
n=10 |
14 |
Correct |
104 ms |
50192 KB |
n=685 |
15 |
Correct |
109 ms |
50192 KB |
n=623 |
16 |
Correct |
77 ms |
50192 KB |
n=973 |
17 |
Correct |
102 ms |
50192 KB |
n=989 |
18 |
Correct |
58 ms |
50192 KB |
n=563 |
19 |
Correct |
58 ms |
50192 KB |
n=592 |
20 |
Correct |
55 ms |
50192 KB |
n=938 |
21 |
Correct |
59 ms |
50192 KB |
n=747 |
22 |
Correct |
53 ms |
50192 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
782 ms |
251128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
n=4 |
2 |
Correct |
43 ms |
47484 KB |
n=3 |
3 |
Correct |
43 ms |
47484 KB |
n=3 |
4 |
Correct |
42 ms |
47484 KB |
n=4 |
5 |
Correct |
43 ms |
47484 KB |
n=4 |
6 |
Correct |
43 ms |
47484 KB |
n=2 |
7 |
Correct |
44 ms |
47492 KB |
n=5 |
8 |
Correct |
38 ms |
47492 KB |
n=8 |
9 |
Correct |
50 ms |
47636 KB |
n=14 |
10 |
Correct |
46 ms |
47648 KB |
n=11 |
11 |
Correct |
103 ms |
49736 KB |
n=50000 |
12 |
Correct |
118 ms |
50192 KB |
n=50000 |
13 |
Correct |
95 ms |
50192 KB |
n=10 |
14 |
Correct |
104 ms |
50192 KB |
n=685 |
15 |
Correct |
109 ms |
50192 KB |
n=623 |
16 |
Correct |
77 ms |
50192 KB |
n=973 |
17 |
Correct |
102 ms |
50192 KB |
n=989 |
18 |
Correct |
58 ms |
50192 KB |
n=563 |
19 |
Correct |
58 ms |
50192 KB |
n=592 |
20 |
Correct |
55 ms |
50192 KB |
n=938 |
21 |
Correct |
59 ms |
50192 KB |
n=747 |
22 |
Correct |
53 ms |
50192 KB |
n=991 |
23 |
Runtime error |
782 ms |
251128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
24 |
Halted |
0 ms |
0 KB |
- |