用户名
增加 1 行删除 1 行
1MoonRebirth1TyTyTT
签名
增加 0 行删除 1 行
1离别是为了更好相遇 AFOed 2025.12个人介绍
增加 53 行删除 1 行
1http://8.149.247.189/1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include<bits/stdc++.h>using namespace std;#define int long longint n,m;int a[200005];void slove() {cin >> n >> m;for (int i = 1;i <= n;i ++) cin >> a[i];priority_queue<int>q;int ans = 0,cnt = 0;for (int i = m;i > 1;i --){cnt += a[i];q.push(a[i]);if (cnt>0) {cnt -= q.top()*2;q.pop();ans++;}}cnt = 0;priority_queue<int,vector<int>,greater<int>>q2;for (int i = m + 1;i <= n;i ++) {cnt += a[i];q2.push(a[i]);if(cnt<0){cnt -= q2.top()*2;q2.pop();ans++;}}cout << ans << '\n';}signed main() {ios::sync_with_stdio(0);cin.tie(0);int T;cin>>T;while (T--) {slove();}return 0;}