-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathc.cpp
49 lines (46 loc) · 756 Bytes
/
c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int T, N, M, A[200000];
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
while(T--){
eat >> N >> M;
for(int i = 0; i < N; i++){
eat >> A[i];
}
M--;
multiset<int> S;
int sum = 0;
int op = 0;
for(int i = M; i > 0; i--){
S.insert(-A[i]);
sum += -A[i];
if(sum < 0){
auto it = S.begin();
int x = -2 * (*it);
sum += x;
S.erase(it);
op++;
}
}
sum = 0;
S.clear();
for(int i = M+1; i < N; i++){
S.insert(A[i]);
sum += A[i];
if(sum < 0){
auto it = S.begin();
int x = -2 * (*it);
sum += x;
S.erase(it);
op++;
}
}
moo << op << endl;
}
}