답안 #584660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584660 2022-06-27T18:42:14 Z sofijavelkovska 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

long long besthub(long long n, long long p, long long a[], long long k)
{
    long long prefix[n];
    for (long long i=0; i<n; i++)
    {
        if (i==0)
            prefix[i]=a[i];
        else
            prefix[i]=prefix[i-1]+a[i];
    }
    long long l=0, r=0, m;
    long long maxrice=0;
    while (r<n)
    {
        m=(r+l)/2;
        long long distanceright, distanceleft;
        distanceright=prefix[r]-prefix[m];
        if (l!=0)
            distanceleft=prefix[m-1]-prefix[l-1];
        else if (m!=0)
            distanceleft=prefix[m-1];
        else
            distanceleft=0;
        long long budget=(a[m]*(m-l)-distanceleft)+(distanceright-a[m]*(r-m));
        if (budget<=k)
        {
            maxrice=max(maxrice, r-l+1);
            r=r+1;
        }
        else
        {
            r=r+1;
            l=l+1;
        }
    }
    return maxrice;
}

int main()
{
    long long n, p, k;
    cin >> n >> p >> k;
    long long a[n];
    for (long long i=0; i<n; i++)
        cin >> a[i];
    cout << besthub(n, p, a, k);

    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccTk93a6.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccJvRhea.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccTk93a6.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status