# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
893223 |
2023-12-26T18:19:37 Z |
vjudge1 |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
455060 KB |
// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>
#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif
using namespace std ;
using ll = long long ;
int32_t main() {
cin.tie(0)->sync_with_stdio(false) ;
int n , k ; cin >> n >> k ;
vector<ll> a(n) ;
for (ll &i : a) cin >> i ;
priority_queue<pair<ll,ll>> q ;
for (int i = 0 ; i < n ; i++) {
q.push({a[i], i}) ;
}
set<ll> st(a.begin(), a.end()) ;
ll sum = accumulate(a.begin(), a.end(), 0ll) ;
if (sum % k || (sum / k) < q.top().first) {
cout << -1 << "\n" ;
return 0 ;
}
vector<vector<int>> res ;
while (q.size() >= k) {
vector<int> cur ;
for (int i = 0 ; i < k ; i++) {
auto [value, ind] = q.top() ;
q.pop() ;
cur.push_back(ind) ;
}
sort(cur.begin(), cur.end(), [&](int i, int j) {
return a[i] < a[j] ;
}) ;
int mn = a[cur[0]] ;
for (int i : cur) {
a[i] -= mn ;
if (a[i]> 0) {
q.push({a[i], i}) ;
}
}
cur.push_back(mn) ;
res.push_back(cur) ;
}
if (q.size()) {
cout << -1 << "\n" ;
return 0 ;
}
cout << res.size() << "\n" ;
for (auto i : res) {
cout << i.back() << ' ' ; i.pop_back() ;
for (int j : i) cout << j + 1 << ' ' ;
cout << "\n" ;
}
return 0 ;
}
// 希望白银
Compilation message
nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:30: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]
30 | while (q.size() >= k) {
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
344 KB |
n=5 |
8 |
Correct |
0 ms |
344 KB |
n=8 |
9 |
Incorrect |
0 ms |
344 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
344 KB |
n=5 |
8 |
Correct |
0 ms |
344 KB |
n=8 |
9 |
Incorrect |
0 ms |
344 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2062 ms |
455060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
344 KB |
n=5 |
8 |
Correct |
0 ms |
344 KB |
n=8 |
9 |
Incorrect |
0 ms |
344 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |