Submission #41089

#TimeUsernameProblemLanguageResultExecution timeMemory
41089IvanCStove (JOI18_stove)C++14
0 / 100
2 ms480 KiB
#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)

stove.cpp: In function 'int func(int)':
stove.cpp:6:6: warning: variable 'ini' set but not used [-Wunused-but-set-variable]
  int ini = -1,fim = -1;
      ^
stove.cpp: In function 'int main()':
stove.cpp:35:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&K);
                      ^
stove.cpp:36:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1;i<=N;i++) scanf("%d",&vetor[i]);
                                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...