QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672047 | #5417. Chat Program | yell | RE | 0ms | 3804kb | C++20 | 1.5kb | 2024-10-24 15:26:37 | 2024-10-24 15:26:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void solve() {
int n, k, m, c, d;
cin >> n >> k >> m >> c >> d;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
auto check = [&](LL mid) -> bool {
vector<LL> b(n + 2);
LL cnt = 0;
for (int i = 1; i <= n; i++) {
b[i] = (a[i] >= mid);
cnt += (a[i] >= mid);
}
if (cnt >= k) {
return true;
}
for (int i = 1; i <= n; i++) {
if (a[i] >= mid) continue;
if (a[i] + c + 1LL * d * (m - 1) < mid) continue;
b[i]++;
if (d == 0) {
b[min(n + 1, i + m)]--;
} else {
LL x = (mid - a[i] - c) / d;
LL r = max(1LL, 1LL * i + m - 1 - x);
b[r]--;
}
}
for (int i = 1; i <= n; i++) {
b[i] += b[i - 1];
if (b[i] + cnt >= k) {
return true;
}
}
return false;
};
LL l = 0, r = 1e18;
while (l < r) {
LL mid = (l + r + 1) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid - 1;
}
}
cout << l << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
6 4 3 1 2 1 1 4 5 1 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
7 3 2 4 0 1 9 1 9 8 1 0
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
8 3 5 0 0 2 0 2 2 1 2 1 8
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: -100
Runtime Error
input:
200000 200000 100000 0 1000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...