# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
89433 |
2018-12-14T10:02:20 Z |
Hideo |
Gift (IZhO18_nicegift) |
C++14 |
|
471 ms |
525312 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e6 + 7;
const int INF = 1e9 + 7;
int a[N], p[N];
int n, k, s;
deque < pair < int, int > > dq[N];
vector < int > ans[N];
main(){
cin >> n >> k;
int mx = -1;
for (int i = 0; i < n; i++){
cin >> a[i];
s += a[i];
mx = max(mx, a[i]);
}
int h = s / k, cs = 0, c = 0;
if (mx > h || s % k != 0){
cout << -1;
return 0;
}
for (int i = 0; i < n; i++){
if(a[i] == 0) continue;
if (cs + a[i] > h){
a[i] -= (h - cs);
dq[c].push_back(make_pair(h - cs, i));
cs = 0; i--; c++;
continue;
}
cs += a[i];
dq[c].push_back(make_pair(a[i], i));
}
int g = 0;
while (s != 0){
int mn = -1;
for (int i = 0; i < k; i++){
if (mn == -1){
mn = dq[i][p[i]].first;
continue;
}
mn = min(mn, dq[i][p[i]].first);
}
ans[g].push_back(mn);
for (int i = 0; i < k; i++){
dq[i][p[i]].first -= mn;
ans[g].push_back(dq[i][p[i]].second + 1);
if(dq[i][p[i]].first == 0)
p[i]++;
}
g++;
s -= (mn * k);
}
cout << g << endl;
int it = 0;
while (it != g){
for (int i = 0; i < ans[it].size(); i++){
cout << ans[it][i] << " ";
}
cout << endl;
it++;
}
}
Compilation message
nicegift.cpp:14:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
nicegift.cpp: In function 'int main()':
nicegift.cpp:61:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans[it].size(); i++){
~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
471 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
471 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
471 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
418 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
471 ms |
525312 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |