답안 #154832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154832 2019-09-25T05:44:10 Z davitmarg 쌀 창고 (IOI11_ricehub) C++17
0 / 100
21 ms 3320 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin (),v.end()
using namespace std;

int n,ans;
LL x[100005],pr[100005],len,s;

LL cost(int l,int r)
{
    int m=(l+r)/2;
    LL res=0;
    res+=(pr[r]-pr[m])-((r-m)*x[m]);
    res+=(pr[m]-pr[l])-((m-l)*x[l]);
    //cout<<l<<" : "<<r<<" = "<<res<<endl;
    return res;
}

bool check(LL k)
{
    int l,r;
    l=1;
    r=k;
    while(r<=n)
    {
        if(cost(l,r)<=s)
            return 1;
        l++;
        r++;
    }
    return 0;
}

int besthub(int N,int L,int X[],LL B)
{
    n=N;
    len=L;
    s=B;
    for(int i=1;i<=n;i++)
        x[i]=X[i-1]-X[0]+1;
    for(int i=1;i<=n;i++)
        pr[i]=pr[i-1]+x[i];
    int l,r,m;
    l=1;
    r=n;
    while(l<=r)
    {
        m=(l+r)/2;
        if(check(m))
        {
            l=m+1;
            ans=m;
        }
        else
            r=m-1;   
    }
    return ans;
}


#ifdef death

int main()
{
    LL N,L,X[102],B;
    cin>>N>>L>>B;
    for(int i=0;i<N;i++)
        cin>>X[i];
    cout<<besthub(N,L,X,B)<<endl;;
	return 0;
}

#endif
 
/*

2
4 5
1 2

4+5+1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 276 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 400 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Incorrect 3 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 6 ms 892 KB Output is correct
3 Correct 19 ms 3320 KB Output is correct
4 Correct 21 ms 3320 KB Output is correct
5 Incorrect 12 ms 1656 KB Output isn't correct
6 Halted 0 ms 0 KB -