Submission #197565

# Submission time Handle Problem Language Result Execution time Memory
197565 2020-01-21T17:12:31 Z Neklixx Split the sequence (APIO14_sequence) C++14
0 / 100
316 ms 3184 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0);
#define FILE freopen("test.in", "r", stdin);
#define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";}
#define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;}
#define debug cout << "-----------------------------------------------" << endl;
#define print1(a) cout << "{ " << a << " }" << endl;
#define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl;
#define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl;
#define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl;
using namespace std;
#define int long long
const int INF = 1e18 + 228;
const int MAXN = 1e5 + 228;
bool used[MAXN];
signed main()
{
#ifdef LOCAL
    FILE;
#endif
    sh;
	int n, k;
	cin >> n >> k;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int aa;
		cin >> aa;
		v.pb(aa);
	}    
	vector<int> p;
	p.pb(0);
	for (int i = 0; i < n; i++) {
		p.pb(p[i] + v[i]);
	}
	vector<int> b;
	b.pb(0);
	b.pb(n - 1);
	int ans = 0;
	vector<int> kek;
	for (int _ = 0; _ < k; _++) {
		int mx = -INF;
		int pos = 0;
		for (int i = 1; i < n; i++) {
			if (used[i])
				continue;
			int r = lower_bound(all(b), i) - b.begin();
			int l = r - 1;
			int lef = p[i] - p[b[l]];
			int rig = p[b[r] + 1] - p[i];
			if (mx < lef * rig) {
				mx = lef * rig;
				pos = i;
			}
		}
		ans += mx;
		used[pos] = 1;
		b.pb(pos - 1);
		b.pb(pos);
		sort(all(b));
		kek.pb(pos);
	}
	cout << ans << endl;
	for (auto to : kek) {
		cout << to << ' ';
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB contestant found the optimal answer: 108 == 108
2 Incorrect 2 ms 376 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 376 KB contestant didn't find the optimal answer: 1093726 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 0 ms 376 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 2 ms 504 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 2 ms 376 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Incorrect 3 ms 376 KB contestant didn't find the optimal answer: 1019625813 < 1019625819
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB contestant didn't find the optimal answer: 21419072 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 760 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2796 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 14 ms 2924 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Incorrect 316 ms 3184 KB contestant didn't find the optimal answer: 497009314607795353 < 497313449256899208
4 Halted 0 ms 0 KB -