/* Name: Author: xiaruize Date: */ #include<bits/stdc++.h> usingnamespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double constint INF = 0x3f3f3f3f; constint MOD = 1000000007; constint N = 2e5 + 10;
// bool st; int t; int n, m; int a[N]; // bool en;
voidsolve() { int res = 0; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; int sum = 0; for (int i = 1; i <= m; i++) sum += a[i]; int tot = 0; tot = sum - a[m]; priority_queue<int> q; q.push(a[m]); for (int i = m - 1; i >= 1; i--) { if (tot < sum) { while (tot < sum) { sum -= q.top() * 2ll; q.pop(); res++; } } q.push(a[i]); tot -= a[i]; } priority_queue<int, vector<int>, greater<int>> p; tot = sum; for (int i = m + 1; i <= n; i++) { p.push(a[i]); tot += a[i]; if (tot < sum) { while (tot < sum) { tot -= p.top() * 2ll; p.pop(); res++; } } } cout << res << endl; }