Chicken dish pertinent records

After doing water problems will be published here

jzoj1443. The minimum and maximum

Greedy easy to think of the following strategies:

The two ordered sequence, each taken from a sequence header, sequence b take the tail, then the head and tail of the sequence b delete a sequence

However, in this way n <= 100,000 case will tle

Note that all weight values ​​of the number of <= 100, then using the records to the tub

ps: Because a wise wrong tone for a long time

#include<bits/stdc++.h>
using namespace std;
int x,y,a[110],b[110],n;
int main(){
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&x,&y);
        a[x]++;b[y]++;
        int s=0,r=101,rs=0,ans=0;
        for(int i=1;i<=100;i++){
            if(!a[i])continue;
            s+=a[i];
            if(rs>=s){
                if(b[r])ans=max(ans,i+r);
                continue;
            }
            while(r&&rs<s){
                if(b[r]&&s-a[i]<rs)ans=max(ans,i+r);
                r--;
                rs+=b[r];
            }
            if(b[r])ans=max(ans,i+r);
        }
        printf("%d\n",ans);
    }
}

 

Guess you like

Origin www.cnblogs.com/rilisoft/p/10945388.html