QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672446 | #5417. Chat Program | yell | WA | 52ms | 5412kb | C++20 | 1.5kb | 2024-10-24 16:51:13 | 2024-10-24 16:51:15 |
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++) {
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);
r = min(1LL * n + 1, r);
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: 3600kb
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: 3612kb
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: 3552kb
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: 0
Accepted
time: 52ms
memory: 5412kb
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 ...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: -100
Wrong Answer
time: 48ms
memory: 5392kb
input:
200000 1 100000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...
output:
100000999999999
result:
wrong answer 1st numbers differ - expected: '100001000000000', found: '100000999999999'