Submission #47817

# Submission time Handle Problem Language Result Execution time Memory
47817 2018-05-07T17:24:09 Z dqhungdl Gift (IZhO18_nicegift) C++17
100 / 100
1312 ms 143488 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];
priority_queue<ii> Q;

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]);
		Q.push(ii(a[i],i));
	}
	if(sum%k!=0||maxn>sum/k)
	{
		cout<<-1;
		return 0;
	}
	int64_t ave=sum/k;
	while(Q.size()>0)
	{
		vector<int64_t> TMP;
		for(int64_t i=1;i<=k;i++)
		{
			int64_t u=Q.top().second;
			Q.pop();
			TMP.push_back(u);
		}
		int64_t tmp=0;
		if(Q.size()>0)
			tmp=Q.top().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)
				Q.push(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 57 ms 70816 KB n=4
2 Correct 56 ms 70820 KB n=3
3 Correct 58 ms 70820 KB n=3
4 Correct 56 ms 70972 KB n=4
5 Correct 57 ms 70972 KB n=4
6 Correct 62 ms 70972 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 57 ms 70816 KB n=4
2 Correct 56 ms 70820 KB n=3
3 Correct 58 ms 70820 KB n=3
4 Correct 56 ms 70972 KB n=4
5 Correct 57 ms 70972 KB n=4
6 Correct 62 ms 70972 KB n=2
7 Correct 57 ms 70972 KB n=5
8 Correct 57 ms 70972 KB n=8
9 Correct 59 ms 70972 KB n=14
10 Correct 58 ms 70972 KB n=11
11 Correct 84 ms 73868 KB n=50000
12 Correct 81 ms 73868 KB n=50000
13 Correct 57 ms 73868 KB n=10
14 Correct 58 ms 73868 KB n=685
15 Correct 58 ms 73868 KB n=623
16 Correct 58 ms 73868 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 57 ms 70816 KB n=4
2 Correct 56 ms 70820 KB n=3
3 Correct 58 ms 70820 KB n=3
4 Correct 56 ms 70972 KB n=4
5 Correct 57 ms 70972 KB n=4
6 Correct 62 ms 70972 KB n=2
7 Correct 57 ms 70972 KB n=5
8 Correct 57 ms 70972 KB n=8
9 Correct 59 ms 70972 KB n=14
10 Correct 58 ms 70972 KB n=11
11 Correct 84 ms 73868 KB n=50000
12 Correct 81 ms 73868 KB n=50000
13 Correct 57 ms 73868 KB n=10
14 Correct 58 ms 73868 KB n=685
15 Correct 58 ms 73868 KB n=623
16 Correct 58 ms 73868 KB n=973
17 Correct 57 ms 73868 KB n=989
18 Correct 58 ms 73868 KB n=563
19 Correct 57 ms 73868 KB n=592
20 Correct 59 ms 73868 KB n=938
21 Correct 57 ms 73868 KB n=747
22 Correct 57 ms 73868 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 681 ms 129800 KB n=1000000
2 Correct 471 ms 129800 KB n=666666
3 Correct 298 ms 129800 KB n=400000
4 Correct 213 ms 129800 KB n=285714
5 Correct 67 ms 129800 KB n=20000
6 Correct 155 ms 129800 KB n=181818
7 Correct 63 ms 129800 KB n=10000
8 Correct 65 ms 129800 KB n=6666
9 Correct 58 ms 129800 KB n=4000
10 Correct 61 ms 129800 KB n=2857
11 Correct 57 ms 129800 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 57 ms 70816 KB n=4
2 Correct 56 ms 70820 KB n=3
3 Correct 58 ms 70820 KB n=3
4 Correct 56 ms 70972 KB n=4
5 Correct 57 ms 70972 KB n=4
6 Correct 62 ms 70972 KB n=2
7 Correct 57 ms 70972 KB n=5
8 Correct 57 ms 70972 KB n=8
9 Correct 59 ms 70972 KB n=14
10 Correct 58 ms 70972 KB n=11
11 Correct 84 ms 73868 KB n=50000
12 Correct 81 ms 73868 KB n=50000
13 Correct 57 ms 73868 KB n=10
14 Correct 58 ms 73868 KB n=685
15 Correct 58 ms 73868 KB n=623
16 Correct 58 ms 73868 KB n=973
17 Correct 57 ms 73868 KB n=989
18 Correct 58 ms 73868 KB n=563
19 Correct 57 ms 73868 KB n=592
20 Correct 59 ms 73868 KB n=938
21 Correct 57 ms 73868 KB n=747
22 Correct 57 ms 73868 KB n=991
23 Correct 681 ms 129800 KB n=1000000
24 Correct 471 ms 129800 KB n=666666
25 Correct 298 ms 129800 KB n=400000
26 Correct 213 ms 129800 KB n=285714
27 Correct 67 ms 129800 KB n=20000
28 Correct 155 ms 129800 KB n=181818
29 Correct 63 ms 129800 KB n=10000
30 Correct 65 ms 129800 KB n=6666
31 Correct 58 ms 129800 KB n=4000
32 Correct 61 ms 129800 KB n=2857
33 Correct 57 ms 129800 KB n=2000
34 Correct 74 ms 129800 KB n=23514
35 Correct 78 ms 129800 KB n=23514
36 Correct 57 ms 129800 KB n=940
37 Correct 57 ms 129800 KB n=2
38 Correct 120 ms 129800 KB n=100000
39 Correct 109 ms 129800 KB n=100000
40 Correct 61 ms 129800 KB n=10
41 Correct 62 ms 129800 KB n=100
42 Correct 61 ms 129800 KB n=1000
43 Correct 801 ms 140288 KB n=1000000
44 Correct 1312 ms 143488 KB n=1000000
45 Correct 828 ms 143488 KB n=666666
46 Correct 490 ms 143488 KB n=400000
47 Correct 68 ms 143488 KB n=2336
48 Correct 807 ms 143488 KB n=285714
49 Correct 700 ms 143488 KB n=181818
50 Correct 88 ms 143488 KB n=40000
51 Correct 74 ms 143488 KB n=20000
52 Correct 63 ms 143488 KB n=10000
53 Correct 115 ms 143488 KB n=6666
54 Correct 59 ms 143488 KB n=4000
55 Correct 290 ms 143488 KB n=2857
56 Correct 56 ms 143488 KB n=2000