2223 - A. 礦砂採集 | TIOJ INFOR Online Judge

本文最後更新於:2024年1月21日 上午

2223 - A. 礦砂採集 | TIOJ INFOR Online Judge

TIOJ-2223.cpp

// Author : ysh
// 12/13/2022 Tue  7:58:35.23
// https://tioj.ck.tp.edu.tw/problems/2223
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,k;cin>>n>>k;
    vector<int>f(k + 1);
    vector<pair<int,int>>v(n);
    for(auto &i : v) {
        cin>>i.first>>i.second;
    }
    sort(v.begin(),v.end(),[] (pair<int,int>a,pair<int,int>b) {
        return a.second > b.second;
    });
    int ans = 0;
    for(auto &i : v) {
        if(k - i.first < 0) {
            ans = ans + i.second * k;
            break;
        }
        ans = ans + i.second * i.first;
        k = k - i.first;
    }
    cout<<ans;
    return 0;
}

2223 - A. 礦砂採集 | TIOJ INFOR Online Judge
http://mysh212.github.io/algosolution/TIOJ-2223.cpp/
作者
ysh
發布於
2022年12月13日
更新於
2024年1月21日
許可協議