이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
int n, k, t;
vector<double> x;
bool check(int s) {
vector<double> X(n);
for (int i = 0; i < n; ++i) X[i] = -x[i] + 2.0 * s * i;
int l = k, r = k;
double mn = X[k], mx = X[k];
while (l || r ^ (n - 1) ) {
if (!l) {
++r;
if (mn > X[r]) return false;
asMx(mx, X[r]);
}
else if (!(r ^ (n - 1) ) ) {
--l;
if (X[l] > mx) return false;
asMn(mn, X[l]);
}
else {
if (X[l - 1] <= mx) {
--l;
asMn(mn, X[l]);
}
else if (mn <= X[r + 1]) {
++r;
asMx(mx, X[r]);
}
else return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef FourLeafClover
freopen("input", "r", stdin);
#endif // FourLeafCLover
cin >> n >> k >> t; --k;
x.assign(n, 0);
for (auto &i : x) cin >> i, i /= t;
int l = 0, r = (int)1e9;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid) ) r = mid;
else l = mid + 1;
}
cout << l << '\n';
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... |