# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41089 | 2018-02-12T15:10:19 Z | IvanC | Stove (JOI18_stove) | C++14 | 2 ms | 480 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Incorrect | 2 ms | 480 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Incorrect | 2 ms | 480 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Incorrect | 2 ms | 480 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |