이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000001
using namespace std;
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,k;
cin>>n>>k;
ll niza[n];
for (ll i = 0; i<n; i++) cin>>niza[i];
set<ll> podelbi;
podelbi.insert(n-1);
ll res = 0;
for (ll ctr = 1; ctr<=k; ctr++) {
vector<pair<pair<ll,ll>,ll>> site;
/// start, end, zbir!
auto itPod = podelbi.begin();
ll zbir = 0, s = 0;
for (ll j = 0; j<n; j++) {
zbir += niza[j];
if (*itPod == j) {
site.pb({{s,j},zbir});
s = j+1;
zbir = 0;
itPod++;
}
}
ll ctr2 = 0, l = site[0].first.first, r = site[0].first.second, zb = site[0].second;
vector<pair<ll,ll>> mozni[ctr];
ll zbMont = 0;
for (ll j = 0; j<n; j++) {
if (r < j) {
ctr2++;
l = site[ctr2].first.first;
r = site[ctr2].first.second;
zb = site[ctr2].second;
zbMont = 0;
}
zbMont += niza[j];
mozni[ctr2].pb({(zb-zbMont)*zbMont,j});
}
vector<pair<ll,ll>> vistina;
for (ll j = 0; j<ctr; j++) sort(mozni[j].rbegin(),mozni[j].rend());
for (ll j = 0; j<ctr; j++) vistina.pb(mozni[j][0]);
sort(vistina.rbegin(), vistina.rend());
podelbi.insert(vistina[0].second);
res += vistina[0].first;
}
cout<<res<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:49:22: warning: variable 'l' set but not used [-Wunused-but-set-variable]
49 | ll ctr2 = 0, l = site[0].first.first, r = site[0].first.second, zb = site[0].second;
| ^
# | 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... |