이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n;
long double k;
cin >> n >> k;
vector <ll> pre(n+1);
pre[0]=0;
vector <int> v(n+1);
for(int i = 1;i <= n;i++){
cin >> v[i];
pre[i] = pre[i-1]+v[i];
}
long double limit = (pre[n]/(k+1));
ll cur = 0;
long double dif = 0;
int l = 0;
ll res = 0;
vector <int> ind;
for(int i = 1;i <=n && ind.size() < k;i++){
if(cur == 0){
cur += v[i];
continue;
}
if(cur + v[i] >= limit+dif){
if(abs((cur + v[i])-limit+dif) == abs(cur-limit+dif)){
if(dif > 0){
res += (pre[i-1] - pre[l])*(pre[n] - pre[i-1]);
l = i-1;
dif += cur - limit;
cur = v[i];
ind.push_back(i-1);
}else{
res += (pre[i] - pre[l])*(pre[n] - pre[i]);
l = i;
dif += (cur + v[i])-limit;
cur = 0;
ind.push_back(i);
}
}else if(abs((cur + v[i])-limit+dif) > abs(cur-limit+dif)){
res += (pre[i-1] - pre[l])*(pre[n] - pre[i-1]);
l = i-1;
dif += cur - limit;
cur = v[i];
ind.push_back(i-1);
}else{
res += (pre[i] - pre[l])*(pre[n] - pre[i]);
l = i;
dif += (cur + v[i])-limit;
cur = 0;
ind.push_back(i);
}
}else{
cur += v[i];
}
}
cout << res << "\n";
for(int i : ind){
cout << i << " ";
}
return 0;
}
# | 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... |