답안 #1003278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003278 2024-06-20T08:29:55 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
컴파일 오류
0 ms 0 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+1];
    pref[0] = 0;
    
    
 
    for(int i = 1; i <= n; i++){
        pref[i] = pref[i-1]+x[i-1];
    }
    
    if(b>=pref[n]){
        return n;
    }
    
  /*  
    for(int i : pref){
        cout << i << " ";
    }
    cout << endl;
    */
    
    int l = 1;
    int final = 1;
    
    for(int r =1; r <= n;r++){
        int m = (l+r)/2;
       
     //   ll val = pref[r] - pref[m] + (pref[m]-pref[max(0,l)]);
       ll val= ((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))));
       //cout <<l << " "<< r << " " << val<<endl;
       
       
       // cout << val << endl;
        if( ((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))))<= b){
           // cout << l << " " << r << endl;
            final = max(final,r-l+1);
        }
        else{
            while(((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m)))) > b && l<r){
                m = (l+r)/2;
                l++;
            }
            m = (l+r)/2;
            if(((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))))<= b){
                 final = max(final,r-l+1);
            }
            
        }
    }
    
    return final;

}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int r,b,l;
    cin >> r >> l>> b;
    int v[r];
    for(int i = 0; i < r; i++){
        cin >> v[i];
    }
    cout << besthub(r,l,v,b)<<endl;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:64:11: warning: unused variable 'val' [-Wunused-variable]
   64 |        ll val= ((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))));
      |           ^~~
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;
      |        ^~~
/usr/bin/ld: /tmp/cceJQY8b.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwwx4nb.o:ricehub.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status