제출 #533601

#제출 시각아이디문제언어결과실행 시간메모리
533601groshiRice Hub (IOI11_ricehub)C++17
100 / 100
17 ms3276 KiB
#include<iostream>
#include "ricehub.h"
using namespace std;
long long prefixy[100100];
long long mam[100100];
long long oblicz(int x,int y)
{
    int srodek=(x+y)/2;
    long long wynik_pomoc=mam[srodek]*(srodek-x)-(prefixy[srodek-1]-prefixy[x-1]);
    long long wynik_pom=(prefixy[y]-prefixy[srodek])-mam[srodek]*(y-srodek);
    return wynik_pomoc+wynik_pom;
}
int besthub(int n,int l,int tak[],long long b)
{
    long long wynik=0,j=1,wynik_pom;
    for(int i=0;i<n;i++)
        mam[i+1]=tak[i];
    for(int i=1;i<=n;i++)
    {
        prefixy[i]=prefixy[i-1];
        prefixy[i]+=mam[i];
    }
    for(int i=1;i<=n;i++)
    {
        wynik_pom=oblicz(i,j+1);
        while(j<n && wynik_pom<=b)
        {
            j++;
            wynik_pom=oblicz(i,j+1);
        }
        if((j-i+1)>wynik)
            wynik=(j-i+1);
    }
    return wynik;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...