Submission #154831

# Submission time Handle Problem Language Result Execution time Memory
154831 2019-09-25T05:43:26 Z davitmarg Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin (),v.end()
using namespace std;

int n,ans;
LL x[100005],pr[100005],len,s;

LL cost(int l,int r)
{
    int m=(l+r)/2;
    LL res=0;
    res+=(pr[r]-pr[m])-((r-m)*x[m]);
    res+=(pr[m]-pr[l])-((m-l)*x[l]);
    //cout<<l<<" : "<<r<<" = "<<res<<endl;
    return res;
}

bool check(LL k)
{
    int l,r;
    l=1;
    r=k;
    while(r<=n)
    {
        if(cost(l,r)<=s)
            return 1;
        l++;
        r++;
    }
    return 0;
}

int besthub(int N,LL L,LL X[],LL B)
{
    n=N;
    len=L;
    s=B;
    for(int i=1;i<=n;i++)
        x[i]=X[i-1]-X[0]+1;
    for(int i=1;i<=n;i++)
        pr[i]=pr[i-1]+x[i];
    int l,r,m;
    l=1;
    r=n;
    while(l<=r)
    {
        m=(l+r)/2;
        if(check(m))
        {
            l=m+1;
            ans=m;
        }
        else
            r=m-1;   
    }
    return ans;
}


#ifdef death

int main()
{
    LL N,L,X[102],B;
    cin>>N>>L>>B;
    for(int i=0;i<N;i++)
        cin>>X[i];
    cout<<besthub(N,L,X,B)<<endl;;
	return 0;
}

#endif
 
/*

2
4 5
1 2

4+5+1

*/

Compilation message

/tmp/ccXC6dZ4.o: In function `main':
grader.cpp:(.text.startup+0x92): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status