其他分享
首页 > 其他分享> > Educational Codeforces Round 117 (Rated for Div. 2) E - Messages

Educational Codeforces Round 117 (Rated for Div. 2) E - Messages

作者:互联网

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n;
pair<int,int> p[N];
pair<double,int> tmp[N];
vector<int> res;
bool cmp(pair<double,int> a,pair<double,int> b){
    return a.first>b.first;
}
int main(){
    scanf("%d",&n);
    int maxi=0;double ans=0;
    for(int i=1;i<=n;i++) scanf("%d%d",&p[i].first,&p[i].second),maxi=max(maxi,p[i].first);
    for(int i=1;i<=20;i++){
        for(int j=1;j<=n;j++){
            tmp[p[j].first].first+=(min(i,p[j].second)*1.0/i);
            tmp[p[j].first].second=p[j].first;
            // cout<<tmp[p[j].first].first<<" "<<tmp[p[j].first].second<<endl;
        }
        sort(tmp,tmp+maxi+1,cmp);
        double tp=0;
        // cout<<tmp[1].first<<endl;
        for(int j=0;j<i;j++){ 
            tp+=tmp[j].first;
            // cout<<tp<<endl;
        }
        // cout<<tp<<endl;
        if(tp>ans){
            ans=tp;
            res.clear();
            for(int j=0;j<i;j++) res.push_back(tmp[j].second);
        }
        for(int j=0;j<=maxi+1;j++)  tmp[j]={0,0};
        
    }
    cout<<res.size()<<endl;
    for(int i=0;i<res.size();i++){
        cout<<res[i]<<" ";
    }cout<<endl;
    
}

标签:tmp,Educational,Rated,cout,int,Messages,ans,pair,first
来源: https://blog.csdn.net/weixin_45714303/article/details/122637600