Submission #423739

# Submission time Handle Problem Language Result Execution time Memory
423739 2021-06-11T12:12:38 Z Apiram Stove (JOI18_stove) C++14
0 / 100
0 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    int64_t n,k;cin>>n>>k;
    vector<int64_t>arr(n);
    for (int i =0;i<n;++i){
        cin>>arr[i];
    }
    --k;
    int64_t left =0,right = arr[n-1]+1;
    while(left<=right){
        int64_t mid = (right+left)>>1;
        int counts=0;
        int64_t prev = arr[0];
        for (int i =1;i<n;++i){
            if (arr[i]+1-prev>mid){
                counts++;
                prev=arr[i];
            }
        }
        if (counts>k){
            left = mid+1;
        }
        else right =  mid - 1;
    }
 
  int64_t ans= 0;
  int64_t prev =arr[0];
    for (int i =1;i<n;++i){
      if (arr[i]+1-prev>left){
        ans+=arr[i-1]+1 - prev;
      prev = arr[i];}}
  	ans+=arr[n-1]+1-prev;
    cout<<ans<<endl;
}
//2 + 4 + 3 + 2 + 1
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -