2020 Jinan ICPC D. Fight against involution

The meaning of the question : given to n people, the number of words written by each person is in a range. At the beginning, everyone chooses the rightmost end of the range as the number of words written by themselves. Each person's score is n-the number of words written is greater than His number
Now let you choose the number of words written by each person, and require that the score be no less than their own choice.
Idea : Take the right endpoint as the first priority and the left endpoint as the second priority, sorted from small to large.
For the same right end point, we make their choices the same, and the left end point should be as small as possible, but it should be greater than or equal to the score of the previous person. It
should be noted that the equal sign can be used
because the ranking is related to the number of words written greater than him. So you can get the same, so that everyone's score is not lower than their original hope.

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
struct node{
    
    
    int s,t;
}a[N];
int main(){
    
    
    int n;cin>>n;
    for(int i=1;i<=n;i++){
    
    
        cin>>a[i].s>>a[i].t;
    }
    sort(a+1,a+n+1,[](node a,node b){
    
    
        if(a.t==b.t) return a.s<b.s;
        return a.t<b.t;
    });
    ll ans=0;
    int last=0;
    for(int i=1;i<=n;i++){
    
    
       int num=1;
       while(i+1<=n && a[i+1].t==a[i].t ) ++i,++num;
       last=max(last,a[i].s);
       ans+=1LL*last*num;
    }
    cout<<ans;
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_43563669/article/details/112341736