You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 2e5 + 50;
|
|
int a[N], t[N];
|
|
#define hlf(x) (((x) + 1) >> 1)
|
|
int main()
|
|
{
|
|
int n, w, k;
|
|
scanf("%d%d%d", &n, &w, &k);
|
|
for (int i = 0; i < n; i++) scanf("%d", a + i);
|
|
for (int i = 0; i < n; i++) scanf("%d", t + i);
|
|
multiset<int> s1, s2;
|
|
int tsum = 0, hsum = 0, ans = 0;
|
|
for (int l = 0, r = 0; r < n; r++)
|
|
{
|
|
s1.insert(t[r]);
|
|
tsum += hlf(t[r]);
|
|
hsum += a[r];
|
|
if (s1.size() > w)
|
|
{
|
|
int x = *s1.begin();
|
|
s2.insert(x);
|
|
tsum += x - hlf(x);
|
|
s1.erase(s1.begin());
|
|
}
|
|
for (; l <= r && tsum > k; hsum -= a[l++])
|
|
if (t[l] < *s1.begin())
|
|
s2.erase(s2.find(t[l])), tsum -= t[l];
|
|
else
|
|
{
|
|
s1.erase(s1.find(t[l]));
|
|
tsum -= hlf(t[l]);
|
|
if (!s2.empty())
|
|
{
|
|
auto x = s2.end();
|
|
--x;
|
|
tsum += hlf(*x) - *x;
|
|
s1.insert(*x);
|
|
s2.erase(x);
|
|
}
|
|
}
|
|
ans = max(ans, hsum);
|
|
}
|
|
printf("%d", ans);
|
|
return 0;
|
|
}
|