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 <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>
#include <ranges>
using namespace std;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 200005
int n, m, a[N];
int main()
{
ShinLena;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
auto bad = [&](int x){
int h = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] - h > m)
{
if (!x--) return 1;
h += m;
}
else h = a[i];
}
return 0;
};
int l = 0, r = n;
while (l <= r)
{
int m = (l+r)/2;
if (bad(m)) l = m + 1;
else r = m - 1;
}
cout << r + 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |