Submission #1009902

# Submission time Handle Problem Language Result Execution time Memory
1009902 2024-06-28T07:32:37 Z Muhammet Split the sequence (APIO14_sequence) C++17
0 / 100
5 ms 1884 KB
#include <bits/stdc++.h>
using namespace std;

#define N 300005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second

ll T, n, k, a[N], p[N];

set <pair<int,int>> s;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		p[i] = p[i-1] + a[i];
	}
	s.insert({1,n});
	ll ans = 0;
	while(k--){
		ll mx = 0, l1 = 0, r1 = 0, ind = 0;
		for(auto i : s){
			int l = i.ff, r = i.ss;
			ll x = 0;
			for(int i = l; i < r; i++){
				x = (p[i]-p[l-1]);
				x *= (p[r]-p[i]);
				if(x > mx){
					mx = x;
					ind = i;
					l1 = l;
					r1 = r;
				}
			}
		}
		s.erase({l1,r1});
		s.insert({l1,ind});
		s.insert({ind+1,r1});
		ans += mx;
	}
	cout << ans;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1884 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -