Submission #378752

# Submission time Handle Problem Language Result Execution time Memory
378752 2021-03-17T03:50:07 Z 8e7 Gift (IZhO18_nicegift) C++14
7 / 100
215 ms 47968 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 1000005
#define pii pair<int, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll a[maxn], pref[maxn];
vector<ll> val;
vector<int> ans[maxn];
int main() {
	io
	ll n, k;
	cin >> n >> k;
	ll m = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		m += a[i];
		pref[i] = m;
	}

	bool poss = m % k == 0;
	ll siz = m / k;

	for (int i = 0;i < n;i++) {
		if (a[i] > siz) {
			poss = false;
			break;
		}
		val.push_back(a[i] % siz);
	}
	sort(val.begin(), val.end());
	val.push_back(siz);
	if (!poss) {
		cout << -1 << endl;
	} else {
		int num = 0;
		ll cur = 0;
		for (int i = 0;i < val.size();i++) {
			if (val[i] - cur > 0) { //[cur, val[i])
				ans[num].push_back(val[i] - cur);
				int ind = upper_bound(pref, pref + n, cur) - pref;
				for (ll j = cur;j < m;j += m / k) {
					while (ind < n && pref[ind] <= j) ind++;
					if (ind < n) ans[num].push_back(ind+1);
				}
				cur = val[i];
				num++;
			}
		}
		cout << num << "\n";
		for (int i = 0;i < num;i++) {
			for (int j:ans[i]) cout << j << " ";
			cout << "\n";
		}
	}
}
/*
4 2
2 3 3 2
 */

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 0;i < val.size();i++) {
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23936 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23936 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Incorrect 16 ms 23788 KB Taken too much stones from the heap
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23936 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Incorrect 16 ms 23788 KB Taken too much stones from the heap
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 47968 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23936 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Incorrect 16 ms 23788 KB Taken too much stones from the heap
10 Halted 0 ms 0 KB -