# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289595 | Doxeno | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
int N;
long long B;
void in(int &n) {
n = 0;
int c = getc_unlocked(stdin), m = 0;
for (; c < '0' || c > '9'; c = getc_unlocked(stdin))
if (c == '-') m = 1;
for (; c >= '0' && c <= '9'; c = getc_unlocked(stdin))
n = (n << 1) + (n << 3) + c - '0';
if (m) n = -n;
}
void lin(long long &n) {
n = 0;
int c = getc_unlocked(stdin), m = 0;
for (; c < '0' || c > '9'; c = getc_unlocked(stdin))
if (c == '-') m = 1;
for (; c >= '0' && c <= '9'; c = getc_unlocked(stdin))
n = (n << 1) + (n << 3) + c - '0';
if (m) n = -n;
}
void out(int n) {
if (!n) putc_unlocked('0', stdout);
int c[11], i = 0;
if (n < 0) { putc_unlocked('-', stdout); n = -n; }
for (; n; n /= 10, i++) c[i] = n % 10 + '0';
for (i--; i >= 0; putc_unlocked(c[i], stdout), i--);
putc_unlocked('\n', stdout);
}
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
in(N); lin(B);
long long risaie[N];
for(int i = 0; i < N; i++)lin(risaie[i]);
int left=0,right=0;
long long spesa = 0;
int m =1;
while(right<N-1){
if(spesa>B){
spesa+=risaie[left]-risaie[(++left+right)/2];
}else{
right++;
spesa+=risaie[right]-risaie[(left+right)/2];
// if(spesa<=B)m=max(,max
}
if(spesa<=B)m=max(m,right-left+1);
}
out(m);
return 0;
}