10pt,咋过
查看原帖
10pt,咋过
317400
Foggy_night楼主2022/12/14 12:44
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
struct cow{
    int x, y;
}a[100005];
bool cmp(cow a_x, cow a_y){
    return a_x.y > a_y.y;
}
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i].x >> a[i].y;
    sort(a+1, a+1+n, cmp);
    int s1 = 1, s2 = n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int t = min(a[s1].x, a[s2].x);
        ans = max(ans, a[s1].y+a[s2].y);
        a[s1].x -= t, a[s2].x -= t;
        if(a[s1].x <= 0) s1++;
        if(a[s2].x <= 0) s2++;
    }
    cout << ans;
    return 0;
}
2022/12/14 12:44
加载中...