Codeforces492C【模擬】

思路:
沒思路,模擬。


果然是要出去打鐵的隊…
這種破題wa5搞的我信心全無…
不打鐵我吃屎!!!


//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long LL;
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define mem(a, b) memset(a, b, sizeof(a))

LL avg;
LL r;
LL n;
struct asd{
    LL a;
    LL b;
}d[100010];
bool cmp(asd x, asd y){
    return x.b < y.b;
}
LL sum, temp;
LL num[100010];
void solve(){
    cin>>n>>r>>avg;
    sum = temp = 0;
    sum = avg * n;
    for(int i=1;i<=n;i++){
        cin>>d[i].a>>d[i].b;
        temp = temp + d[i].a;
    }
    sort(d+1, d+n+1, cmp);
    num[0] = 0;
    for(int i=1;i<=n;i++)
        num[i] = num[i-1] + r - d[i].a;
    LL yp = sum - temp;
    LL res = 0;
    if(yp>0){
        int p = 0;
        for(int i=1;i<=n;i++){
            if(num[i] <= yp){
                res = (r - d[i].a) * d[i].b + res;
                p = i;
            }
        }
        if(num[p] == yp){
            cout<<res<<endl;
            return;
        }
        if(p < n){
            yp = yp - num[p];
            res = res + d[p+1].b * yp;
            cout<<res<<endl;
            return;
        }
    }
    cout<<res<<endl;
}

int main()
{
    solve();
    return 0;
}
發佈了799 篇原創文章 · 獲贊 125 · 訪問量 38萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章