首页 > 其他分享 >C. RationalLee

C. RationalLee

时间:2024-03-01 22:23:28浏览次数:16  
标签:sort int auto cin long ans RationalLee

https://codeforces.com/problemset/problem/1369/C

This is a hard problem on codefores with a diffcuilty score of 1400
It can also be solved by using the priciple of greediness.

void solve(){
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (auto& x : a){
        cin >> x;
    }

    sort(a.rbegin(), a.rend());

    vector<int> d(k);
    for (auto&x : d){
        cin >> x;
    }

    sort(d.begin(), d.end());
    long long ans = 0;
    for (int i = 0; i < k; ++i){
        ans += a[i];
    }

    for (int i = 0, j = k - 1; i < k; ++i){
        if (d[i] == 1){
            ans += a[i];
        }
        else{
            j += d[i] - 1;
            ans += a[j];
        }
    }

    cout << ans << '\n';
}

标签:sort,int,auto,cin,long,ans,RationalLee
From: https://www.cnblogs.com/yxcblogs/p/18048080

相关文章