Submission #346313

#TimeUsernameProblemLanguageResultExecution timeMemory
346313MefarnisRice Hub (IOI11_ricehub)C++14
Compilation error
0 ms0 KiB
#include <algorithm> #include "ricehub.h" using namespace std; long long getCost(int l , int r , int x[], long long sum[]) { int m = (l+r) >> 1; long long cost = 0; if(l < m) cost += (m-l) * (long long) x[m-1] - (sum[m-1] - sum[l-1]); if(m < r) cost += (sum[r] - sum[m]) - (r-m) * (long long) x[m-1]; return cost; } int besthub(int n, int xmax, int x[], long long budget) { int ans = 0; long long sum[n+1]; sum[0] = 0; for( int i = 1 ; i <= n ; i++ ) sum[i] = sum[i-1] + x[i-1]; for( int l = 1 , r = 1 ; l <= n ; l++ ) { r = max(l,r); while(r < n && getCost(l,r+1,x,sum) <= budget) r++; ans = max(ans,r-l+1); } return ans; } int main() { int n = 5; int xmax = 20; int x[5]; x[0] = 1; x[1] = 2; x[2] = 10; x[3] = 12; x[4] = 14; long long b = 6; int ans = besthub(n,xmax,x,b); printf("%d\n",ans); return 0; }

Compilation message (stderr)

ricehub.cpp: In function 'int main()':
ricehub.cpp:42:2: error: 'printf' was not declared in this scope
   42 |  printf("%d\n",ans);
      |  ^~~~~~
ricehub.cpp:3:1: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
    2 | #include "ricehub.h"
  +++ |+#include <cstdio>
    3 | using namespace std;