답안 #224588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224588 2020-04-18T13:13:07 Z my99n 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

long long s[100100];

int sum(int l, int r) {
    if (l == 0) return s[r];
    return s[r] - s[l - 1];
}

int besthub(int n, int L, int x[], long long b) {
    s[0] = x[0];
    for (int i = 1; i < n; i++) s[i] = 0;
    for (int i = 1; i < n; i++) s[i] = x[i] + s[i - 1];
    int l = 0, r = 0, ans = 1;

    for (int i = 0; i < n; i++) {
        int l = 0, r = n - 1;
        while (l < r) {
            int mid = (l + r) / 2;
            int med = (i + mid) / 2;
            int left = s[med] * (med - i + 1) - sum(i, med);
            int right = sum(med + 1, mid) - s[med] * (mid - med);
            if (left + right > b)
                r = mid;
            else
                l = mid + 1;
        }
        ans = max(ans, l - i + 1);
    }
    return ans;
}

int main() {
    int n, l, b;
    scanf("%d %d %d", &n, &l, &b);
    int x[n];
    for (int i = 0; i < n; i++) scanf("%d", &x[i]);
    printf("%d", besthub(n, l, x, b));
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:16:9: warning: unused variable 'l' [-Wunused-variable]
     int l = 0, r = 0, ans = 1;
         ^
ricehub.cpp:16:16: warning: unused variable 'r' [-Wunused-variable]
     int l = 0, r = 0, ans = 1;
                ^
ricehub.cpp: In function 'int main()':
ricehub.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &l, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ricehub.cpp:39:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < n; i++) scanf("%d", &x[i]);
                                 ~~~~~^~~~~~~~~~~~~
/tmp/ccZqNY3u.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccdzkxrg.o:ricehub.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status