Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz(x) (int)(x).size()
- #define li long long
- #define ld long double
- #define x first
- #define y second
- #define pt pair<int, int>
- #define pll pair<ll, ll>
- #define forn(i, t) for(int i = 0; i < (t); i++)
- #define fore(i, f, t) for(int i = (f); i < (t); i++)
- #define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- using namespace std;
- const int INF = 1e9;
- const int MOD = 1e9 + 7;
- const li INF64 = 1e18;
- const ld EPS = 1e-7;
- mt19937 myrand(time(NULL));
- const int N = 200 * 1000 + 13;
- int n, w, d;
- pt a[N];
- bool read(){
- if(scanf("%d%d%d", &n, &w, &d) != 3)
- return 0;
- forn(i, n)
- scanf("%d", &a[i].y);
- forn(i, n)
- scanf("%d", &a[i].x);
- return 1;
- }
- void solve(){
- multiset<pt> cur, cura;
- int ans = 0;
- int sum = 0, suma = 0, l = 0, res = 0;
- forn(i, n){
- cur.insert(a[i]);
- sum += a[i].x;
- res += a[i].y;
- while (sum + suma > d){
- if (sz(cura) < w && !cur.empty()){
- pt tmp = *cur.rbegin();
- cura.insert(tmp);
- sum -= tmp.x;
- sum += (tmp.x + 1) / 2;
- cur.erase(cur.find(tmp));
- continue;
- }
- if (cur.find(a[l]) != cur.end()){
- cur.erase(cur.find(a[l]));
- sum -= a[l].x;
- }
- else if (cura.find(a[l]) != cur.end()){
- cura.erase(cura.find(a[l]));
- suma -= (a[l].x + 1) / 2;
- }
- res -= a[l].y;
- l++;
- }
- ans = max(ans, res);
- }
- printf("%d\n", ans);
- }
- int main(){
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #endif
- while(read())
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement