이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
vector<int> numbers;
priority_queue<pair<int, pair<int, int> > > pieces;
set<int> splits;
int findSplit(int l, int r) {
int totalSum = 0;
for (int i = l; i < r; i++) {
totalSum += numbers[i];
}
int lSum = 0;
int rSum = totalSum;
int ans = 0;
int i;
for (i = l; i < r; i++) {
lSum += numbers[i];
rSum -= numbers[i];
if (lSum * rSum > ans)
ans = lSum * rSum;
if (lSum * rSum < ans) {
pieces.push(make_pair(lSum, make_pair(l, i)));
pieces.push(make_pair(rSum, make_pair(i, r)));
splits.insert(i);
return ans;
}
}
splits.insert(i);
return ans;
}
int main() {
int nAmount, sAmount;
cin >> nAmount >> sAmount;
int totalSum = 0;
for (int i = 0; i < nAmount; i++) {
int x; cin >> x;
numbers.push_back(x);
totalSum += x;
}
pieces.push(make_pair(totalSum, make_pair(0, nAmount)));
int ans = 0;
for (int i = 0; i < sAmount; i++) {
pair<int, pair<int, int> > topPiece = pieces.top();
pieces.pop();
ans += findSplit(topPiece.second.first, topPiece.second.second);
}
cout << ans << endl;
for (int num : splits)
cout << num << " ";
cout << endl;
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... |