제출 #499573

#제출 시각아이디문제언어결과실행 시간메모리
499573aryan12Rice Hub (IOI11_ricehub)C++17
100 / 100
13 ms2504 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int rice, int len, int a[], long long b) {
    long long pref[rice], suf[rice];
    pref[0] = a[0];
    for(long long i = 1; i < rice; i++) {
      pref[i] = pref[i - 1] + a[i];
    }
    long long right = 0, ans = 0;
    for(long long left = 0; left < rice; left++) {
      right = max(right, left);
      while(right != rice) {
        long long mid = (left + right) / 2;
        long long cur_ans;
        if(left != 0) cur_ans = a[mid] * (mid - left + 1) - pref[mid] + pref[left - 1];
        else cur_ans = a[mid] * (mid - left + 1) - pref[mid];
        if(mid != 0) cur_ans += pref[right] - pref[mid - 1] - a[mid] * (right - mid + 1);
        else cur_ans += pref[right] - a[mid] * (right - mid + 1);
        //cout << "l = " << left << ", mid = " << mid << ", right = " << right << ", cur_ans = " << cur_ans << "\n";
        if(cur_ans <= b) {
          ans = max(ans, right - left + 1);
        }
        else {
          break;
        }
        right++;
      }
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:6:27: warning: unused variable 'suf' [-Wunused-variable]
    6 |     long long pref[rice], suf[rice];
      |                           ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...