QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#794212 | #5417. Chat Program | proking | TL | 0ms | 0kb | C++14 | 2.5kb | 2024-11-30 12:57:38 | 2024-11-30 12:57:39 |
answer
#include <bits/stdc++.h>
#define F(i, a, b) for (ll i = a; i <= b; i ++)
#define G(i, a, b) for (ll i = a; i >= b; i --)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define get getchar()
#define putc putchar
#define outarr(a, L, R) { prllf(#a"[%d..%d]", L, R); F(i, L, R) W(a[i]), putc(' ') ; putc('\n'); }
#define out1(x) { printf(#x" = "), W(x), putc('\n'); }
#define out2(x, y) { printf(#x" = "), W(x), printf(" "#y" = "), W(y), putc('\n'); }
#define out3(x, y, z) { printf(#x" = "), W(x), printf(" "#y" = "), W(y), printf(" "#z" = "), W(z), putc('\n'); }
#define out4(x, y, z, w) { printf(#x" = %d", x); printf(" "#y" = %d", y); printf(" "#z" = %d", z), printf(" "#w" = %d", w), putc('\n'); }
#define Assert(x, y) { if (!(x)) { printf("Wrong %d", y); exit(0); } }
#define mem(a, b) memset(a, b, sizeof a)
#define mec(a, b) memcpy(a, b, sizeof a)
#define pi pair<ll, ll>
#define V vector <ll>
#define ll long long
#define get getchar()
#define pb push_back
#define putc putchar
#define pb push_back
#define db double
#define fi first
#define se second
using namespace std;
template <typename Int>
void R(Int &x) {
char c = get; x = 0; Int t = 1;
for (; !isdigit(c); c = get) t = (c == '-' ? -1 : t);
for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename Int>
void W(Int x) {
if (x < 0) { putc('-'); x = - x; }
if (x > 9) W(x / 10); putc(x % 10 + '0');
}
using namespace std;
const ll N = 2e5 + 10;
ll n, k, m, c, d, a[N], f[N];
bool ok(ll p) {
// out1(p);
F(i, 1, n) f[i] = 0;
ll Max = 0, cnt = 0;
F(i, 1, n) {
// out2(a[i], p);
if (a[i] >= p) {
cnt ++;
continue;
}
// out1(d);
if (d == 0) {
if (c + a[i] >= p) {
if (i + m - 1 <= n)
f[i] ++, f[i + 1] --;
}
continue;
}
ll w = a[i] + c >= p ? 0 : ((p - c - a[i] - 1) / d + 1);
// if (p == 6) {
// out4(p - c - a[i] - 1, d, w, a[i]);
// out2(max(1, i - m + 1), max(1, i - w + 1));
// putc('\n');
// }
if (w <= m)
f[max(1, i - m + 1)] ++, f[max(1, i - w + 1)] --;
}
F(i, 1, n) f[i] += f[i - 1], mx(Max, cnt + f[i]);
// out2(cnt, Max);
return Max >= k;
}
signed main() {
freopen("data.in","r",stdin);
R(n), R(k), R(m), R(c), R(d);
F(i, 1, n) R(a[i]);
ll l = 0, r = 2e18, ans = -1;
while (l <= r) {
ll md = l + r >> 1;
if (ok(md))
ans = md, l = md + 1;
else
r = md - 1;
}
W(ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
6 4 3 1 2 1 1 4 5 1 4