ji
作者:
好好好呵呵
,
2023-04-15 16:01:10
,
所有人可见
,
阅读 181
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int T;
const int N = 2e5 + 10;
int a[N];
int p[N];
int n,m;
void solve()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
priority_queue<int> pos;
long long t = 0;
int ans = 0;
for (int i = m; i >= 1; i--)
{
if (p[i] + t < p[m])
{
while (p[i] + t < p[m])
{
t += 2ll * pos.top();
pos.pop();
ans++;
}
}
if (a[i] > 0)
pos.push(a[i]);
}
priority_queue<int, vector<int>, greater<>> neg;
t = 0;
for (int i = m + 1; i <= n; i++)
{
if (a[i] < 0)
neg.push(a[i]);
if (p[i] - t < p[m])
{
while (p[i] - t < p[m])
{
t += 2ll * neg.top();
neg.pop();
ans++;
}
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin >> T;
while(T--)
solve();
}