Submission #745283

# Submission time Handle Problem Language Result Execution time Memory
745283 2023-05-19T17:47:48 Z maks007 Split the sequence (APIO14_sequence) C++14
0 / 100
553 ms 2400 KB
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;

#define int long long 

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	order_set S;
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for(auto &i : a) cin >> i;
	int pref[n];
	function <int(int,int)> get=[&](int l, int r) {
		if(l == 0) return pref[r];
		return pref[r] - pref[l - 1]; 	
	};
	function <int(int)> Sum=[&](int pos) {
		auto pered = S.upper_bound(pos);
		auto zad = --S.upper_bound(pos);
		int sumPered = get(pos + 1, *pered);
		int sumZad = get(*zad+1, pos);
		return sumPered * sumZad;	
	};
	pref[0] = a[0];
	for(int i = 1; i < n; i ++) pref[i] = a[i] + pref[i-1];
	S.insert(-1);
	S.insert(n-1);
	set <int> ans;
	vector <int> res;
	int sum = 0;
	for(int step = 0; step < k; step ++) {
		int mx = -LLONG_MAX, pos;
		for(int i = 0; i < n-1; i ++) {
			if(ans.count(i) == 1) continue;
			if(Sum(i) > mx) {
				mx = Sum(i);
				pos = i;
			}
//			cout << i << " " << Sum(i) << "\n";
		}
//		cout << "\n";
		sum += mx;
		ans.insert(pos);
		res.push_back(pos);
		S.insert(pos);
	}
	cout << sum << "\n";
	for(auto i : res) cout << i+1 << " ";
	return 0;
}
/*
7 3
4 1 3 4 0 2 3
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB contestant found the optimal answer: 108 == 108
2 Incorrect 1 ms 316 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB contestant didn't find the optimal answer: 1093726 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 320 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 2 ms 212 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 1 ms 212 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Incorrect 2 ms 212 KB contestant didn't find the optimal answer: 1019625813 < 1019625819
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB contestant didn't find the optimal answer: 21419072 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2004 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 12 ms 1992 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Incorrect 553 ms 2400 KB contestant didn't find the optimal answer: 497009314607795353 < 497313449256899208
4 Halted 0 ms 0 KB -