#include <iostream>
#include <algorithm>
#include <set>
#include <deque>
#include <queue>
using namespace std;
int arr[107];
int main(){
int n, l, r, k;
cin >> n >> l >> r >> k;
l--; r--;
int s = 0;
auto cmp = [](int i, int j){ return arr[i] < arr[j]; };
auto cmpv = [](int i, int j){ return arr[i] > arr[j]; };
priority_queue<int, vector<int>, decltype(cmp)> p(cmp);
priority_queue<int, vector<int>, decltype(cmpv)> q(cmpv);
for(int i = 0; i < n; i++){
cin >> arr[i];
if(l <= i && i <= r){
p.push(i);
s += arr[i];
}
else q.push(i);
}
int m = s;
while(k && q.size()){
if(abs(q.top() - p.top()) > k){
q.pop();
continue;
}
k -= abs(q.top() - p.top());
s -= arr[p.top()];
p.pop();
s += arr[q.top()];
q.pop();
m = min(m, s);
}
cout << m << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |