답안 #880700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880700 2023-11-29T22:06:15 Z andro 쌀 창고 (IOI11_ricehub) C++14
0 / 100
1000 ms 1372 KB
#include <bits/stdc++.h>
#include "ricehub.h"
//#define int long long
using namespace std;
int besthub(int R, int L, int X[], long long B){
    int pref[R+1];
    pref[0]=0;
    for(int i=1;i<=R;i++)pref[i]=pref[i-1]+X[i];
    int ans=0;
    map<int,int>cnt;
    for(int i=1;i<=R;i++)cnt[X[i]]++;
    for(int i=1;i<=R;i++){
        long long LL=0LL,RR=(long long)1e15,P=0;
        while(LL<=RR){
            long long s=(LL+RR)/2;
            long long c=0;
            for(int j=1;j<=R;j++){
                if(X[j]>=X[i]&&X[j]<=X[i]+s){
                    c+=X[j]-X[i];
                }
                else if(X[j]<=X[i]&&X[j]>=X[i]-s&&X[j]<=X[i]){
                    c+=X[i]-X[j];
                }
            }
            /*
            int l=1,r=i,p=-1;
            while(l<=r){
                int mid=(l+r)/2;
                if(abs(X[mid]-X[i])<=s){
                    r=mid-1;
                    p=mid;
                }
                else {
                    r=mid-1;
                }
            }
            int x=i-p+1;
            c+=(X[i])*x-pref[i]-pref[p-1];
            l=i+1,r=R,p=-1;
            while(l<=r){
                int mid=(l+r)/2;
                if(abs(X[i]-X[mid])<=s){
                    l=mid+1;
                    p=mid;
                }
                else {
                    r=mid-1;
                }
            }
            if(p!=-1){
                x=p-i;
                c+=(pref[p]-pref[i])-X[i]*x;
            }*/
            if(c<=B){
                LL=s+1;
                P=s;
            }
            else {
                RR=s-1;
            }
            //cout<<i<<" "<<s<<" "<<c;
            //cout<<endl;
        }
        int u=0;
        /*
        for(int j=1;j<=R;j++){
            if(abs(X[i]-X[j])<=p)c+=abs(X[i]-X[j]);
            if(abs(X[i]-X[j])<=p)u++;
        }
        for(int j=1;j<=R;j++){
            if(abs(X[i]-X[j])==p+1){
                c+=abs(X[i]-X[j]);
                if(c<=B)u++;
            }
        }*/
        int l=1,r=i,p=-1;
        long long s=0;
        while(l<=r){
            int mid=(l+r)/2;
            if(abs(X[mid]-X[i])<=P){
                r=mid-1;
                p=mid;
            }
            else {
                l=mid+1;
            }
        }
        s+=((i-p+1)*X[i])-(pref[i]-pref[p-1]);
        u+=i-p+1;
        l=i+1,r=R,p=-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(abs(X[mid]-X[i])<=P){
                r=mid-1;
                p=mid;
            }
            else {
                l=mid+1;
            }
        }
        if(p!=-1){
            u+=p-i;
            s+=(pref[p]-pref[i])-X[i]*(p-i);
        }
        // |x-y|=P
        //! kolko ih ima na intervalu [a[i],a[i]+mid]+[a[i]-mid,a[i]]
        for(int j=1;j<=R;j++){
            if(abs(X[j]-X[i])==P+1){
                s+=abs(X[j]-X[i]);
                if(s<=B)u++;
            }
        }
        //cout<<i<<" "<<s;
        //cout<<endl;
        ans=max(ans,u);
    }
    return ans;
}/*
signed main(){
    int X[4]={0,10,12,14};
    cout<<besthub(3,14,X,6);
}*/
/*
1 3
2 3
3 3
3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1029 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -