Submission #504055

# Submission time Handle Problem Language Result Execution time Memory
504055 2022-01-09T15:22:18 Z Newtech66 Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
using lol=long long int;
#define endl "\n"
const lol mod1=1e9+7,mod2=998244353;
const lol inf=1e18+8;
const double eps=1e-12;
const double PI=acos(-1.0);
const int N=2e5+5;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool ok(const vector<lol>& p,int n,lol B,int k)
{
    auto query=[&](int l,int r){
        if(l>r) return 0ll;
        return p[r]-(l?p[l-1]:0);
    };
    for(int i=0;i+k-1<n;i++)
    {
        int pos=i+k/2;
        lol chk=0;
        if(i<=pos)  chk+=(pos-i+1)*query(pos,pos)-query(i,pos);
        if(pos+1<=i+k-1)    chk+=query(pos+1,i+k-1)-(i+k-1-pos)*query(pos,pos);
        if(chk<=B)  return true;
    }
    return false;
}

int besthub(int R,int L,int X[],lol B)
{
    vector<lol> p{X,X+R};
    partial_sum(p.begin(),p.end(),p.begin());
    int l=1,r=R,mid,ans;
    while(l<=r)
    {
        mid=l+(r-l)/2;
        if(ok(p,R,B,mid))
        {
            ans=mid;
            l=mid+1;
        }else   r=mid-1;
    }
    return ans;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int _=1;
//cin>>_;
while(_--)
{
    int R,L;
    lol B;
    cin>>R>>L>>B;
    int X[R];
    for(int i=0;i<R;i++)    cin>>X[i];
    cout<<besthub(R,L,X,B);
}
return 0;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, lol)':
ricehub.cpp:47:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |     return ans;
      |            ^~~
/usr/bin/ld: /tmp/cc0CZ9M1.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccv2zUA5.o:ricehub.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status