# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41089 | IvanC | Stove (JOI18_stove) | C++14 | 2 ms | 480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int vetor[MAXN],N,K;
int func(int val){
int ini = -1,fim = -1;
int tot = 0;
for(int i = 1;i<=N;i++){
if(vetor[i] + 1 > fim){
ini = vetor[i];
fim = vetor[i] + val;
tot += 1;
}
}
return tot;
}
int calc(int val){
int ini = -1,fim = -1,last = -1;
int tot = 0;
for(int i = 1;i<=N;i++){
if(vetor[i] + 1 > fim){
tot += last - ini;
ini = vetor[i];
fim = vetor[i] + val;
last = vetor[i] + 1;
}
else{
last = vetor[i] + 1;
}
}
tot += last - ini;
return tot;
}
int main(){
scanf("%d %d",&N,&K);
for(int i = 1;i<=N;i++) scanf("%d",&vetor[i]);
int ini = 1,fim = (int)1e9,meio,resp = -1;
while(ini <= fim){
meio = (ini+fim)/2;
if(func(meio) <= K){
resp = meio;
fim = meio - 1;
}
else{
ini = meio + 1;
}
}
printf("%d\n",calc(resp));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |