Skip to content

Commit

Permalink
2163
Browse files Browse the repository at this point in the history
  • Loading branch information
lzl124631x committed Mar 2, 2022
1 parent c8d31b5 commit 0863af9
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ public:
long long minimumDifference(vector<int>& A) {
priority_queue<int> L; // storing the smallest N digits in the first part
priority_queue<int,vector<int>, greater<>> R; // storing the greatest N digits in the right part
long N = A.size() / 3, left = 0, right = 0, ans = LLONG_MAX;
vector<long> tmp(A.size());
for (int i = A.size() - 1; i >= N; --i) { // calculate the greatest N digits in the right part
long N = A.size() / 3, ans = LLONG_MAX;
vector<long> right(A.size());
for (long i = A.size() - 1, sum = 0; i >= N; --i) { // calculate the greatest N digits in the right part
R.push(A[i]);
right += A[i];
sum += A[i];
if (R.size() > N) {
right -= R.top();
sum -= R.top();
R.pop();
}
if (R.size() == N) tmp[i] = right; // `tmp[i]` is the maximum sum of `N` digits in `A[i:]`
if (R.size() == N) right[i] = sum; // `right[i]` is the maximum sum of `N` digits in `A[i:]`
}
for (int i = 0; i < A.size() - N; ++i) {
for (long i = 0, left = 0; i < A.size() - N; ++i) {
L.push(A[i]);
left += A[i];
if (L.size() > N) {
left -= L.top();
L.pop();
}
if (L.size() == N) ans = min(ans, left - tmp[i + 1]);
if (L.size() == N) ans = min(ans, left - right[i + 1]);
}
return ans;
}
Expand Down

0 comments on commit 0863af9

Please sign in to comment.