#include <bits/stdc++.h>
using namespace std;
int moment[100001];
int main ()
{
ios :: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int lungime , limita;
cin >> lungime >> limita;
for (int indice = 1 ; indice <= lungime ; indice++)
{ cin >> moment[indice]; }
int64_t stanga = 0 , dreapta = 1000000000000000 , rezultat = 0;
while (stanga <= dreapta)
{
const int64_t termen = (stanga + dreapta) >> 1;
pair <int64_t , int> minim = {-moment[1] + termen + 1 , 0};
for (int capat = 1 ; capat <= lungime ; capat++)
{
const int64_t candidat = minim.first + moment[capat];
minim = min(minim , {candidat - moment[capat + 1] + termen + 1 , minim.second + 1});
if (capat == lungime) {
if (minim.second + 1 <= limita) { dreapta = termen - 1; rezultat = candidat - 1LL * limita * termen; }
else { stanga = termen + 1; }
}
}
}
cout << rezultat;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |