Submission #715553

# Submission time Handle Problem Language Result Execution time Memory
715553 2023-03-27T08:08:04 Z vjudge1 Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
int besthub(int n,int l,int x[],int b){
    int cost,mid,mx_cost,ans;
    vector<int> prefixSum(l,0);

    for(int i=1;i<=n;i++)prefixSum[i] = prefixSum[i-1]+x[i-1];
    //for(int i=1;i<=n;i++)cout<<prefixSum[i]<<" "; cout<<endl;
    for(int st=1;st<=n;st++){
        for(int en=st;en<=n;en++){
            mid = (st+en)/2;
            cost = (mid-st)*x[mid]-(prefixSum[mid-1]-prefixSum[st-1]) + (prefixSum[en]-prefixSum[mid])-(en-mid)*x[mid];

            if(cost <= b)ans = max(ans,en-st+1);
            //cout<<st<<" "<<en<<" "<<cost<<endl;
        }
    }
    return ans;


}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, int)':
ricehub.cpp:3:5: error: 'vector' was not declared in this scope
    3 |     vector<int> prefixSum(l,0);
      |     ^~~~~~
ricehub.cpp:3:12: error: expected primary-expression before 'int'
    3 |     vector<int> prefixSum(l,0);
      |            ^~~
ricehub.cpp:5:26: error: 'prefixSum' was not declared in this scope
    5 |     for(int i=1;i<=n;i++)prefixSum[i] = prefixSum[i-1]+x[i-1];
      |                          ^~~~~~~~~
ricehub.cpp:10:37: error: 'prefixSum' was not declared in this scope
   10 |             cost = (mid-st)*x[mid]-(prefixSum[mid-1]-prefixSum[st-1]) + (prefixSum[en]-prefixSum[mid])-(en-mid)*x[mid];
      |                                     ^~~~~~~~~
ricehub.cpp:12:32: error: 'max' was not declared in this scope
   12 |             if(cost <= b)ans = max(ans,en-st+1);
      |                                ^~~
ricehub.cpp:2:18: warning: unused variable 'mx_cost' [-Wunused-variable]
    2 |     int cost,mid,mx_cost,ans;
      |                  ^~~~~~~