Submission #674265

# Submission time Handle Problem Language Result Execution time Memory
674265 2022-12-23T15:22:03 Z Ahmed57 Sparklers (JOI17_sparklers) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;
int n,k;int t;
int arr[100001];

bool check(int mid){
    int l = k-1 , r = k+1 , lin = k , rin = k;
    int te = t , tel = t , ter = t , suml = 0, sumr = 0;
    int minl = 1000000000.0;
    int minr = 1000000000.0;
    while(1){
        int mi = 0;
        bool ss = 0;
        while(l>=0){
            int dis = (arr[l+1]-arr[l])/2;
            int tim = dis/mid;
            if(tel<tim){
                break;
            }
            minl = min(minl,tel-tim);
            tel-=tim;tel+=t;
            suml+=t-tim;
            if(suml>0){
                ss = 1;
                lin = l;
                minr+=suml;
                te = tel;
                ter += suml;
                suml = 0;
                minl = 1000000000.0;
            }
            l--;
        }while(r<n){
            int dis = (arr[r]-arr[r-1])/2;
            int tim = dis/mid;
            if(ter<tim){
                break;
            }
            minr = min(minr,ter-tim);
            ter-=tim;
            ter+=t;
            sumr+=t-tim;
            if(sumr>0){
                ss = 1;
                rin = r;
                minl+=sumr;
                te = ter;
                tel += sumr;
                sumr = 0;
                minr = 1000000000.0;
            }
            r++;
        }
        if(lin==0&&rin==n-1)return 1;
        if(l==-1&&r==n&&((minr>=te-suml)||(minl>=te-sumr))){
            return 1;
        }
        if(ss==0)return 0;
    }
    return 1;
}
int main(){
    cin>>n>>k>>t;
    k--;
    for(int i = 0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    int l = 0 , r = 1e9 , ans = 0;
    while(l<=r){
        int mid = (l+r)/2;
        if(check(mid)){
            r = mid-1;
            ans = mid;
        }else l = mid+1;
    }
    cout<<ans;
}

Compilation message

sparklers.cpp: In function 'bool check(int)':
sparklers.cpp:13:13: warning: unused variable 'mi' [-Wunused-variable]
   13 |         int mi = 0;
      |             ^~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -