0
点赞
收藏
分享

微信扫一扫

【IDEA构建Docker镜像】

船长_Kevin 2024-08-09 阅读 16
算法

G-旅途的终点_河南萌新联赛2024第(一)场:河南农业大学 (nowcoder.com)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc u << 1
#define rc u << 1 | 1

void solve();

const int N = 1e6 + 10;


signed main() {
    IOS;
    ll t = 1;
//    cin >> t;
    while (t--)
        solve();
    return 0;
}

void solve() {
    ll n, m, k; cin >> n >> m >> k;
    priority_queue<ll,vector<ll>,greater<>> q;
    ll sum = 0,sum_mianyi = 0;
    ll ans = 0;
    for(int i = 1; i <= n; ++ i)
    {   ll x; cin >> x;
        sum += x;
        sum_mianyi += x;
        q.push(x);
        while(q.size() > k)
        {
            sum_mianyi -= q.top();
            q.pop();
        }
        if(sum - sum_mianyi >= m)
        {
            break;
        }
        ans = i;
    }
    cout << ans << endl;
}
举报

相关推荐

0 条评论