# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
47816 |
2018-05-07T17:21:58 Z |
dqhungdl |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
192340 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int64_t,int64_t> ii;
int64_t n,k,top=0,a[1000005],rs[3000005];
vector<int64_t> g[3000005];
set<ii> s;
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
//freopen("TEST.OUT","w",stdout);
cin>>n>>k;
int64_t sum=0,maxn=0;
for(int64_t i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
maxn=max(maxn,a[i]);
s.insert(ii(a[i],i));
}
if(sum%k!=0||maxn>sum/k)
{
cout<<-1;
return 0;
}
int64_t ave=sum/k;
while(s.size()>0)
{
vector<int64_t> TMP;
for(int64_t i=1;i<=k;i++)
{
int64_t u=(*s.rbegin()).second;
s.erase(s.find(*s.rbegin()));
TMP.push_back(u);
}
int64_t tmp=0;
if(s.size()>0)
tmp=(*s.rbegin()).first;
int64_t lim=min(a[TMP.back()],ave-tmp);
ave-=lim;
rs[++top]=lim;
g[top]=TMP;
for(int64_t i=0;i<TMP.size();i++)
{
a[TMP[i]]-=lim;
if(a[TMP[i]]>0)
s.insert(ii(a[TMP[i]],TMP[i]));
}
}
cout<<top<<"\n";
for(int64_t i=1;i<=top;i++)
{
cout<<rs[i]<<' ';
for(int64_t j=0;j<g[i].size();j++)
cout<<g[i][j]<<' ';
cout<<"\n";
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int64_t i=0;i<TMP.size();i++)
~^~~~~~~~~~~
nicegift.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int64_t j=0;j<g[i].size();j++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
70776 KB |
n=4 |
2 |
Correct |
59 ms |
70872 KB |
n=3 |
3 |
Correct |
69 ms |
71004 KB |
n=3 |
4 |
Correct |
62 ms |
71052 KB |
n=4 |
5 |
Correct |
57 ms |
71052 KB |
n=4 |
6 |
Correct |
63 ms |
71200 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
70776 KB |
n=4 |
2 |
Correct |
59 ms |
70872 KB |
n=3 |
3 |
Correct |
69 ms |
71004 KB |
n=3 |
4 |
Correct |
62 ms |
71052 KB |
n=4 |
5 |
Correct |
57 ms |
71052 KB |
n=4 |
6 |
Correct |
63 ms |
71200 KB |
n=2 |
7 |
Correct |
60 ms |
71200 KB |
n=5 |
8 |
Correct |
56 ms |
71200 KB |
n=8 |
9 |
Correct |
60 ms |
71200 KB |
n=14 |
10 |
Correct |
57 ms |
71200 KB |
n=11 |
11 |
Correct |
96 ms |
75504 KB |
n=50000 |
12 |
Correct |
89 ms |
75504 KB |
n=50000 |
13 |
Correct |
57 ms |
75504 KB |
n=10 |
14 |
Correct |
60 ms |
75504 KB |
n=685 |
15 |
Correct |
56 ms |
75504 KB |
n=623 |
16 |
Correct |
58 ms |
75504 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
70776 KB |
n=4 |
2 |
Correct |
59 ms |
70872 KB |
n=3 |
3 |
Correct |
69 ms |
71004 KB |
n=3 |
4 |
Correct |
62 ms |
71052 KB |
n=4 |
5 |
Correct |
57 ms |
71052 KB |
n=4 |
6 |
Correct |
63 ms |
71200 KB |
n=2 |
7 |
Correct |
60 ms |
71200 KB |
n=5 |
8 |
Correct |
56 ms |
71200 KB |
n=8 |
9 |
Correct |
60 ms |
71200 KB |
n=14 |
10 |
Correct |
57 ms |
71200 KB |
n=11 |
11 |
Correct |
96 ms |
75504 KB |
n=50000 |
12 |
Correct |
89 ms |
75504 KB |
n=50000 |
13 |
Correct |
57 ms |
75504 KB |
n=10 |
14 |
Correct |
60 ms |
75504 KB |
n=685 |
15 |
Correct |
56 ms |
75504 KB |
n=623 |
16 |
Correct |
58 ms |
75504 KB |
n=973 |
17 |
Correct |
63 ms |
75504 KB |
n=989 |
18 |
Correct |
62 ms |
75504 KB |
n=563 |
19 |
Correct |
59 ms |
75504 KB |
n=592 |
20 |
Correct |
56 ms |
75504 KB |
n=938 |
21 |
Correct |
56 ms |
75504 KB |
n=747 |
22 |
Correct |
58 ms |
75504 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1196 ms |
160016 KB |
n=1000000 |
2 |
Correct |
767 ms |
160016 KB |
n=666666 |
3 |
Correct |
444 ms |
160016 KB |
n=400000 |
4 |
Correct |
318 ms |
160016 KB |
n=285714 |
5 |
Correct |
72 ms |
160016 KB |
n=20000 |
6 |
Correct |
209 ms |
160016 KB |
n=181818 |
7 |
Correct |
64 ms |
160016 KB |
n=10000 |
8 |
Correct |
63 ms |
160016 KB |
n=6666 |
9 |
Correct |
60 ms |
160016 KB |
n=4000 |
10 |
Correct |
62 ms |
160016 KB |
n=2857 |
11 |
Correct |
59 ms |
160016 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
70776 KB |
n=4 |
2 |
Correct |
59 ms |
70872 KB |
n=3 |
3 |
Correct |
69 ms |
71004 KB |
n=3 |
4 |
Correct |
62 ms |
71052 KB |
n=4 |
5 |
Correct |
57 ms |
71052 KB |
n=4 |
6 |
Correct |
63 ms |
71200 KB |
n=2 |
7 |
Correct |
60 ms |
71200 KB |
n=5 |
8 |
Correct |
56 ms |
71200 KB |
n=8 |
9 |
Correct |
60 ms |
71200 KB |
n=14 |
10 |
Correct |
57 ms |
71200 KB |
n=11 |
11 |
Correct |
96 ms |
75504 KB |
n=50000 |
12 |
Correct |
89 ms |
75504 KB |
n=50000 |
13 |
Correct |
57 ms |
75504 KB |
n=10 |
14 |
Correct |
60 ms |
75504 KB |
n=685 |
15 |
Correct |
56 ms |
75504 KB |
n=623 |
16 |
Correct |
58 ms |
75504 KB |
n=973 |
17 |
Correct |
63 ms |
75504 KB |
n=989 |
18 |
Correct |
62 ms |
75504 KB |
n=563 |
19 |
Correct |
59 ms |
75504 KB |
n=592 |
20 |
Correct |
56 ms |
75504 KB |
n=938 |
21 |
Correct |
56 ms |
75504 KB |
n=747 |
22 |
Correct |
58 ms |
75504 KB |
n=991 |
23 |
Correct |
1196 ms |
160016 KB |
n=1000000 |
24 |
Correct |
767 ms |
160016 KB |
n=666666 |
25 |
Correct |
444 ms |
160016 KB |
n=400000 |
26 |
Correct |
318 ms |
160016 KB |
n=285714 |
27 |
Correct |
72 ms |
160016 KB |
n=20000 |
28 |
Correct |
209 ms |
160016 KB |
n=181818 |
29 |
Correct |
64 ms |
160016 KB |
n=10000 |
30 |
Correct |
63 ms |
160016 KB |
n=6666 |
31 |
Correct |
60 ms |
160016 KB |
n=4000 |
32 |
Correct |
62 ms |
160016 KB |
n=2857 |
33 |
Correct |
59 ms |
160016 KB |
n=2000 |
34 |
Correct |
82 ms |
160016 KB |
n=23514 |
35 |
Correct |
85 ms |
160016 KB |
n=23514 |
36 |
Correct |
57 ms |
160016 KB |
n=940 |
37 |
Correct |
58 ms |
160016 KB |
n=2 |
38 |
Correct |
137 ms |
160016 KB |
n=100000 |
39 |
Correct |
143 ms |
160016 KB |
n=100000 |
40 |
Correct |
59 ms |
160016 KB |
n=10 |
41 |
Correct |
59 ms |
160016 KB |
n=100 |
42 |
Correct |
62 ms |
160016 KB |
n=1000 |
43 |
Correct |
1619 ms |
192340 KB |
n=1000000 |
44 |
Execution timed out |
2092 ms |
192340 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |