Submission #89491

# Submission time Handle Problem Language Result Execution time Memory
89491 2018-12-15T06:26:36 Z antimirage Gift (IZhO18_nicegift) C++17
100 / 100
870 ms 137560 KB
#include <bits/stdc++.h>

#define pb emplace_back
#define mk make_pair
#define fr first
#define sc second

using namespace std;

const int N = 1e6 + 5;

int n, k, sz, l[N];

long long sum, ar[N], mx, cn, mn[N];

vector < pair <long long, int> > vec[N];

vector < vector <int> > ans;

main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		scanf("%lld", &ar[i]), sum += ar[i], mx = max(mx, ar[i]);
		
	if (mx > sum / k || sum % k != 0){
		puts("-1");
		return 0;
	}
	sum /= k;
	for (int i = 1; i <= n; i++)
	{
		if (cn + ar[i] > sum){
			
			vec[sz].pb( make_pair(sum - cn, i) );
			ar[i] -= (sum - cn);
			i--;
			cn = 0;
			sz++;
		}
		else{
			cn += ar[i];
			vec[sz].pb( make_pair(ar[i], i) );
		}
		if (cn == sum){
			cn = 0;
			sz++;
		}
	}
	assert(sz == k);
	
	while (1)
	{
		ans.pb( vector <int>() );
		
		mn[ans.size()] = 2e18;
		
		for (int j = 0; j < sz; j++)
			mn[ans.size()] = min(vec[j][ l[j] ].fr, mn[ans.size()]);
		
		for (int j = 0; j < sz; j++)
		{
			ans.back().pb( vec[j][ l[j] ].sc );
			
			vec[j][ l[j] ].fr -= mn[ ans.size() ];
			
			if (vec[j][ l[j] ].fr == 0)
				l[j]++;
		}
		if (l[0] >= (int)vec[0].size() ) break;
	}
	cn = 0;
	cout << ans.size() << endl;
	for (auto it : ans)
	{
		printf("%lld ", mn[ cn + 1 ]);
		for (auto to : it)
			printf("%d ", to);
			
		puts("");
		cn++;
	}
}
/**
4 2
2 3 3 2
**/

Compilation message

nicegift.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:24:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &ar[i]), sum += ar[i], mx = max(mx, ar[i]);
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB n=4
2 Correct 21 ms 23952 KB n=3
3 Correct 21 ms 23952 KB n=3
4 Correct 21 ms 23952 KB n=4
5 Correct 22 ms 23952 KB n=4
6 Correct 22 ms 23952 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB n=4
2 Correct 21 ms 23952 KB n=3
3 Correct 21 ms 23952 KB n=3
4 Correct 21 ms 23952 KB n=4
5 Correct 22 ms 23952 KB n=4
6 Correct 22 ms 23952 KB n=2
7 Correct 22 ms 24016 KB n=5
8 Correct 22 ms 24016 KB n=8
9 Correct 28 ms 24016 KB n=14
10 Correct 27 ms 24056 KB n=11
11 Correct 62 ms 28584 KB n=50000
12 Correct 54 ms 28584 KB n=50000
13 Correct 22 ms 28584 KB n=10
14 Correct 26 ms 28584 KB n=685
15 Correct 26 ms 28584 KB n=623
16 Correct 22 ms 28584 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB n=4
2 Correct 21 ms 23952 KB n=3
3 Correct 21 ms 23952 KB n=3
4 Correct 21 ms 23952 KB n=4
5 Correct 22 ms 23952 KB n=4
6 Correct 22 ms 23952 KB n=2
7 Correct 22 ms 24016 KB n=5
8 Correct 22 ms 24016 KB n=8
9 Correct 28 ms 24016 KB n=14
10 Correct 27 ms 24056 KB n=11
11 Correct 62 ms 28584 KB n=50000
12 Correct 54 ms 28584 KB n=50000
13 Correct 22 ms 28584 KB n=10
14 Correct 26 ms 28584 KB n=685
15 Correct 26 ms 28584 KB n=623
16 Correct 22 ms 28584 KB n=973
17 Correct 26 ms 28584 KB n=989
18 Correct 27 ms 28584 KB n=563
19 Correct 27 ms 28584 KB n=592
20 Correct 24 ms 28584 KB n=938
21 Correct 29 ms 28584 KB n=747
22 Correct 28 ms 28584 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 508 ms 93248 KB n=1000000
2 Correct 321 ms 93248 KB n=666666
3 Correct 188 ms 93248 KB n=400000
4 Correct 457 ms 93248 KB n=285714
5 Correct 35 ms 93248 KB n=20000
6 Correct 386 ms 93248 KB n=181818
7 Correct 29 ms 93248 KB n=10000
8 Correct 64 ms 93248 KB n=6666
9 Correct 23 ms 93248 KB n=4000
10 Correct 222 ms 93248 KB n=2857
11 Correct 24 ms 93248 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB n=4
2 Correct 21 ms 23952 KB n=3
3 Correct 21 ms 23952 KB n=3
4 Correct 21 ms 23952 KB n=4
5 Correct 22 ms 23952 KB n=4
6 Correct 22 ms 23952 KB n=2
7 Correct 22 ms 24016 KB n=5
8 Correct 22 ms 24016 KB n=8
9 Correct 28 ms 24016 KB n=14
10 Correct 27 ms 24056 KB n=11
11 Correct 62 ms 28584 KB n=50000
12 Correct 54 ms 28584 KB n=50000
13 Correct 22 ms 28584 KB n=10
14 Correct 26 ms 28584 KB n=685
15 Correct 26 ms 28584 KB n=623
16 Correct 22 ms 28584 KB n=973
17 Correct 26 ms 28584 KB n=989
18 Correct 27 ms 28584 KB n=563
19 Correct 27 ms 28584 KB n=592
20 Correct 24 ms 28584 KB n=938
21 Correct 29 ms 28584 KB n=747
22 Correct 28 ms 28584 KB n=991
23 Correct 508 ms 93248 KB n=1000000
24 Correct 321 ms 93248 KB n=666666
25 Correct 188 ms 93248 KB n=400000
26 Correct 457 ms 93248 KB n=285714
27 Correct 35 ms 93248 KB n=20000
28 Correct 386 ms 93248 KB n=181818
29 Correct 29 ms 93248 KB n=10000
30 Correct 64 ms 93248 KB n=6666
31 Correct 23 ms 93248 KB n=4000
32 Correct 222 ms 93248 KB n=2857
33 Correct 24 ms 93248 KB n=2000
34 Correct 44 ms 93248 KB n=23514
35 Correct 42 ms 93248 KB n=23514
36 Correct 27 ms 93248 KB n=940
37 Correct 28 ms 93248 KB n=2
38 Correct 149 ms 93248 KB n=100000
39 Correct 133 ms 93248 KB n=100000
40 Correct 23 ms 93248 KB n=10
41 Correct 26 ms 93248 KB n=100
42 Correct 32 ms 93248 KB n=1000
43 Correct 775 ms 132044 KB n=1000000
44 Correct 870 ms 137560 KB n=1000000
45 Correct 714 ms 137560 KB n=666666
46 Correct 562 ms 137560 KB n=400000
47 Correct 237 ms 137560 KB n=2336
48 Correct 471 ms 137560 KB n=285714
49 Correct 392 ms 137560 KB n=181818
50 Correct 280 ms 137560 KB n=40000
51 Correct 260 ms 137560 KB n=20000
52 Correct 244 ms 137560 KB n=10000
53 Correct 232 ms 137560 KB n=6666
54 Correct 224 ms 137560 KB n=4000
55 Correct 238 ms 137560 KB n=2857
56 Correct 221 ms 137560 KB n=2000