답안 #1115581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115581 2024-11-20T16:21:20 Z vjudge1 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

int R;
ll L, B;
vector<ll> X;
vector<ll> prefixSum;

bool check(int K) {
    int N = R;
    for (int i = 0; i <= N - K; ++i) {
        int j = i + K - 1;
        int m = (i + j) / 2;

        int leftCount = m - i;
        ll sumLeft = (leftCount > 0 ? prefixSum[m - 1] - (i > 0 ? prefixSum[i - 1] : 0) : 0);

        int rightCount = j - m;
        ll sumRight = (rightCount > 0 ? prefixSum[j] - prefixSum[m] : 0);

        ll totalCost = X[m] * (ll)leftCount - sumLeft + sumRight - X[m] * (ll)rightCount;

        if (totalCost <= B) {
            return true;
        }
    }
    return false;
}

int main() {
    cin >> R >> L >> B;
    X.resize(R);
    for (int i = 0; i < R; ++i) {
        cin >> X[i];
    }
    prefixSum.resize(R);
    prefixSum[0] = X[0];
    for (int i = 1; i < R; ++i) {
        prefixSum[i] = prefixSum[i - 1] + X[i];
    }

    int low = 1, high = R;
    int ans = 0;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (check(mid)) {
            ans = mid;
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/cccKqOht.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccdAr9Hv.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cccKqOht.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