#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll MAX = 1LL << 60;
ostream& operator<<(ostream& o, pll p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll iceil(ll a, ll b){
return (a + b - 1) / b;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
priority_queue<pll> pq;
for(int i = 1; i <= n; i++){
ll a;
cin >> a;
pq.push(mp(a, i));
}
vector<pair<ll, vector<int>>> ans;
while(pq.size() >= k){
vector<pll> t;
for(int i = 0; i < k; i++){
t.eb(pq.top());
pq.pop();
}
ll tmp = 1;
ans.eb(mp(tmp, vector<int>()));
for(pll i : t){
ans.back().S.eb(i.S);
i.F -= tmp;
if(i.F) pq.push(i);
}
}
if(!pq.empty()){
cout << "-1\n";
return 0;
}
cout << ans.size() << "\n";
for(auto& i : ans){
cout << i.F << " ";
printv(i.S, cout);
}
return 0;
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
45 | while(pq.size() >= k){
| ~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 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 |
0 ms |
364 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 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 |
0 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
5 ms |
1132 KB |
n=8 |
9 |
Correct |
8 ms |
1384 KB |
n=14 |
10 |
Correct |
5 ms |
1132 KB |
n=11 |
11 |
Correct |
40 ms |
4964 KB |
n=50000 |
12 |
Correct |
39 ms |
4964 KB |
n=50000 |
13 |
Correct |
28 ms |
3936 KB |
n=10 |
14 |
Correct |
27 ms |
3424 KB |
n=685 |
15 |
Correct |
30 ms |
3676 KB |
n=623 |
16 |
Correct |
17 ms |
2272 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 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 |
0 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
5 ms |
1132 KB |
n=8 |
9 |
Correct |
8 ms |
1384 KB |
n=14 |
10 |
Correct |
5 ms |
1132 KB |
n=11 |
11 |
Correct |
40 ms |
4964 KB |
n=50000 |
12 |
Correct |
39 ms |
4964 KB |
n=50000 |
13 |
Correct |
28 ms |
3936 KB |
n=10 |
14 |
Correct |
27 ms |
3424 KB |
n=685 |
15 |
Correct |
30 ms |
3676 KB |
n=623 |
16 |
Correct |
17 ms |
2272 KB |
n=973 |
17 |
Correct |
27 ms |
2784 KB |
n=989 |
18 |
Correct |
12 ms |
1128 KB |
n=563 |
19 |
Correct |
19 ms |
1512 KB |
n=592 |
20 |
Correct |
21 ms |
1384 KB |
n=938 |
21 |
Correct |
16 ms |
1384 KB |
n=747 |
22 |
Correct |
17 ms |
1384 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2084 ms |
257548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
0 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 |
0 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
5 ms |
1132 KB |
n=8 |
9 |
Correct |
8 ms |
1384 KB |
n=14 |
10 |
Correct |
5 ms |
1132 KB |
n=11 |
11 |
Correct |
40 ms |
4964 KB |
n=50000 |
12 |
Correct |
39 ms |
4964 KB |
n=50000 |
13 |
Correct |
28 ms |
3936 KB |
n=10 |
14 |
Correct |
27 ms |
3424 KB |
n=685 |
15 |
Correct |
30 ms |
3676 KB |
n=623 |
16 |
Correct |
17 ms |
2272 KB |
n=973 |
17 |
Correct |
27 ms |
2784 KB |
n=989 |
18 |
Correct |
12 ms |
1128 KB |
n=563 |
19 |
Correct |
19 ms |
1512 KB |
n=592 |
20 |
Correct |
21 ms |
1384 KB |
n=938 |
21 |
Correct |
16 ms |
1384 KB |
n=747 |
22 |
Correct |
17 ms |
1384 KB |
n=991 |
23 |
Execution timed out |
2084 ms |
257548 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |