# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378762 |
2021-03-17T03:55:48 Z |
i_am_noob |
Gift (IZhO18_nicegift) |
C++17 |
|
1243 ms |
95136 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<b; ++i)
#define rep3(i,a,b) for(int i=a; i>=b; --i)
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define pii pair<int,int>
#define pb push_back
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&... y){cerr << x << ' ',_do(y...);}
#else
#define bug(...) 826
#endif
const int maxn=1000005;
const int mod=1000000007;
int n,k,a[maxn];
priority_queue<pii> pq;
vector<vector<int>> res;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> n >> k;
rep(n) cin >> a[i];
int sum=0,m;
rep(n) sum+=a[i];
if(sum%k){
cout << "-1\n";
return 0;
}
m=sum/k;
rep(n) pq.push({a[i],i});
while(sz(pq)>=k){
if(pq.top().first>m){
cout << "-1\n";
return 0;
}
vector<int> vec;
rep(k){
auto [x,y]=pq.top();
pq.pop();
vec.pb(y);
}
if(pq.empty()){
res.pb({a[vec[0]]});
for(auto i: vec) res.back().pb(i+1);
break;
}
int val=min(a[vec.back()],m-pq.top().first);
res.pb({val});
for(auto i: vec) res.back().pb(i+1);
for(auto i: vec) a[i]-=val;
for(auto i: vec) if(a[i]) pq.push({a[i],i});
m-=val;
rep(n) bug(a[i]);
}
if(!pq.empty()){
cout << "-1\n";
return 0;
}
cout << sz(res) << "\n";
for(auto& vec1: res){
for(auto i: vec1) cout << i << ' ';
cout << "\n";
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:20:18: warning: statement has no effect [-Wunused-value]
20 | #define bug(...) 826
| ^~~
nicegift.cpp:69:16: note: in expansion of macro 'bug'
69 | rep(n) bug(a[i]);
| ^~~
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
29 ms |
4092 KB |
n=50000 |
12 |
Correct |
24 ms |
3688 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
29 ms |
4092 KB |
n=50000 |
12 |
Correct |
24 ms |
3688 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
17 |
Correct |
1 ms |
364 KB |
n=989 |
18 |
Correct |
1 ms |
364 KB |
n=563 |
19 |
Correct |
1 ms |
364 KB |
n=592 |
20 |
Correct |
1 ms |
364 KB |
n=938 |
21 |
Correct |
1 ms |
364 KB |
n=747 |
22 |
Correct |
1 ms |
364 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
600 ms |
73788 KB |
n=1000000 |
2 |
Correct |
388 ms |
39740 KB |
n=666666 |
3 |
Correct |
204 ms |
22352 KB |
n=400000 |
4 |
Correct |
135 ms |
13904 KB |
n=285714 |
5 |
Correct |
9 ms |
1136 KB |
n=20000 |
6 |
Correct |
99 ms |
9180 KB |
n=181818 |
7 |
Correct |
5 ms |
752 KB |
n=10000 |
8 |
Correct |
3 ms |
748 KB |
n=6666 |
9 |
Correct |
2 ms |
492 KB |
n=4000 |
10 |
Correct |
4 ms |
748 KB |
n=2857 |
11 |
Correct |
1 ms |
492 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
29 ms |
4092 KB |
n=50000 |
12 |
Correct |
24 ms |
3688 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
17 |
Correct |
1 ms |
364 KB |
n=989 |
18 |
Correct |
1 ms |
364 KB |
n=563 |
19 |
Correct |
1 ms |
364 KB |
n=592 |
20 |
Correct |
1 ms |
364 KB |
n=938 |
21 |
Correct |
1 ms |
364 KB |
n=747 |
22 |
Correct |
1 ms |
364 KB |
n=991 |
23 |
Correct |
600 ms |
73788 KB |
n=1000000 |
24 |
Correct |
388 ms |
39740 KB |
n=666666 |
25 |
Correct |
204 ms |
22352 KB |
n=400000 |
26 |
Correct |
135 ms |
13904 KB |
n=285714 |
27 |
Correct |
9 ms |
1136 KB |
n=20000 |
28 |
Correct |
99 ms |
9180 KB |
n=181818 |
29 |
Correct |
5 ms |
752 KB |
n=10000 |
30 |
Correct |
3 ms |
748 KB |
n=6666 |
31 |
Correct |
2 ms |
492 KB |
n=4000 |
32 |
Correct |
4 ms |
748 KB |
n=2857 |
33 |
Correct |
1 ms |
492 KB |
n=2000 |
34 |
Correct |
17 ms |
2412 KB |
n=23514 |
35 |
Correct |
20 ms |
2412 KB |
n=23514 |
36 |
Correct |
1 ms |
492 KB |
n=940 |
37 |
Correct |
1 ms |
364 KB |
n=2 |
38 |
Correct |
62 ms |
5604 KB |
n=100000 |
39 |
Correct |
60 ms |
5604 KB |
n=100000 |
40 |
Correct |
1 ms |
364 KB |
n=10 |
41 |
Correct |
1 ms |
364 KB |
n=100 |
42 |
Correct |
3 ms |
604 KB |
n=1000 |
43 |
Correct |
795 ms |
91828 KB |
n=1000000 |
44 |
Correct |
1243 ms |
95136 KB |
n=1000000 |
45 |
Correct |
820 ms |
54680 KB |
n=666666 |
46 |
Correct |
441 ms |
32912 KB |
n=400000 |
47 |
Correct |
11 ms |
1132 KB |
n=2336 |
48 |
Correct |
750 ms |
51020 KB |
n=285714 |
49 |
Correct |
655 ms |
48596 KB |
n=181818 |
50 |
Correct |
29 ms |
2664 KB |
n=40000 |
51 |
Correct |
14 ms |
1516 KB |
n=20000 |
52 |
Correct |
11 ms |
1008 KB |
n=10000 |
53 |
Correct |
60 ms |
6124 KB |
n=6666 |
54 |
Correct |
5 ms |
620 KB |
n=4000 |
55 |
Correct |
240 ms |
20844 KB |
n=2857 |
56 |
Correct |
3 ms |
620 KB |
n=2000 |