답안 #1003165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003165 2024-06-20T07:03:40 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
0 / 100
2 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pf push_front
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>

/*
int besthub(int n, int last, int x[], ll b){
    

    int ans = 0;
    int l , r;
    for(int i = 0; i < n; i++){
        
        l = i - (lower_bound(x.begin(), x.end(), max(0LL,x[i]-b))- x.begin());
        r =  upper_bound(x.begin(), x.end(), min((ll) last, x[i]+b)) - x.begin() - (i+1);
       // cout << x[i] << " " <<l << " " << r << endl;
        ans = max(l+r+1,ans);
    }
    
    return ans;

}

*/

int besthub(int n, int last, int x[], ll b){
    

    ll ans = 0;
    
    ll cnt;
    ll pref[n];
    pref[0] = 0;
    
    for(int i = 1; i  < n; i++){
        pref[i] = pref[i-1] + (x[i]-x[i-1]);
    }
    
    
    
    ll l = 0;
    ll final = 1;
    
    for(int r =0; r < n;r++){
        if(pref[r]-pref[l]<= b){
           // cout << l << " " << r << endl;
           
            final = max(final,r-l+1);
             r++;
        }
        else{
            while(pref[r]-pref[l]>b && l<r){
                l++;
            }
            
        }
    }
    
    return final;

}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:34:8: warning: unused variable 'ans' [-Wunused-variable]
   34 |     ll ans = 0;
      |        ^~~
ricehub.cpp:36:8: warning: unused variable 'cnt' [-Wunused-variable]
   36 |     ll cnt;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -