# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
930925 | AtabayRajabli | Split the sequence (APIO14_sequence) | C++17 | 235 ms | 2392 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// author : a1abay
#define pb push_back
#define all(v) v.begin(), v.end()
#define int ll
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b / (__gcd(a, b)))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int inf = 1e9 + 7;
const int inff = 1e18 + 7;
const int sz = 1e5 + 5;
using namespace std;
void open(string s, string f)
{
freopen((s + ".txt").c_str(), "r", stdin);
freopen((f + ".txt").c_str(), "w", stdout);
}
int n, k, a[sz], p[sz];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// open("in", "out");
cin >> n >> k;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i <= n; i++)p[i] = p[i - 1] + a[i];
set<int> splits;
splits.insert(0);
splits.insert(n);
int ans = 0;
vector<int> cuts;
while(k--)
{
int mx = -1, cut = -1;
for(int i = 1; i <= n; i++)
{
auto it = splits.lower_bound(i);
int l = *--it + 1, r = *++it;
if(l > r)continue;
int lx = p[i] - p[l - 1];
int rx = p[r] - p[i];
if(lx * rx > mx)
{
mx = lx * rx;
cut = i;
}
}
ans += mx;
splits.insert(cut);
cuts.pb(cut);
}
cout << ans << '\n';
for(int i : cuts)cout << i << " ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |