#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e18 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
vector<vector<ll> > ans;
ll n, k;
cin >> n >> k;
priority_queue<pair<ll, ll> > pq;
for(ll i = 0; i < n; i ++) {
ll a;
cin >> a;
if(a != 0) {
pq.push({-a, i});
}
}
while(pq.size() >= k) {
vector<pair<ll, ll> > curr;
ll get = mod;
for(ll i = 0; i < k; i ++) {
chkmin(get, -pq.top().first);
curr.push_back(pq.top()); pq.pop();
}
ans.resize(ans.size() + 1);
ans.back().push_back(get);
for(auto &it : curr) {
ans.back().push_back(it.second + 1);
it.first += get;
if(it.first > 0) {
pq.push({it});
}
}
}
if(pq.size() != 0) {
cout << -1 << endl;
return 0;
}
cout << ans.size() << endl;
for(auto it : ans) {
for(auto itt : it) {
cout << itt << " ";
}
cout << endl;
}
return 0;
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:28: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 'll' {aka 'long long int'} [-Wsign-compare]
28 | while(pq.size() >= k) {
| ~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
n=4 |
2 |
Incorrect |
0 ms |
384 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
n=4 |
2 |
Incorrect |
0 ms |
384 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
n=4 |
2 |
Incorrect |
0 ms |
384 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
630 ms |
65720 KB |
n=1000000 |
2 |
Correct |
391 ms |
34364 KB |
n=666666 |
3 |
Correct |
238 ms |
19924 KB |
n=400000 |
4 |
Incorrect |
116 ms |
9428 KB |
Jury has the answer but participant has not |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
n=4 |
2 |
Incorrect |
0 ms |
384 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |