QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672037 | #5417. Chat Program | yell | RE | 0ms | 3600kb | C++20 | 1.5kb | 2024-10-24 15:25:14 | 2024-10-24 15:25:14 |
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<int> b(n + 2);
int 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
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: 3600kb
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: 3580kb
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 ...