Untitled

 avatar
unknown
plain_text
a year ago
1.9 kB
5
Indexable
#include <bits/stdc++.h>
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#define newline cout << "\n";

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);



    int t;
    cin >> t;
    for(int j=1; j<=t; j++)
    {

        ll n, pos, dis;
        cin >> n >> pos >> dis;
        vector< pair<ll,ll> >vec(n);

        for(int i=0; i<n; i++)
        {
            cin >> vec[i].first;
        }
        for(int i=0; i<n; i++)
        {
            cin >> vec[i].second;
        }
        sort(vec.begin(),vec.end());

        ll p=pos;
        ll d=dis;
        ll ans=INT_MIN;
        for(int k=-1; k<n; k++)
        {
            p=pos;
            d=dis;
            ll prof=0,prof2=0;
            for(int i=k; i>=0; i--)
            {
                if(i<0) break;
                d-=abs(p-vec[i].first);

                if(d>=0)
                {
                    prof+=vec[i].second;
                    p=vec[i].first;
                }
                else
                {
                    prof+=d;
                    p=vec[i].first;
                }
            }

            for(int i=k+1; i<n; i++)
            {
                if(i>=n) break;
                d-=abs(p-vec[i].first);

                if(d>=0)
                {
                    prof+=vec[i].second;
                    p=vec[i].first;
                }
                else
                {
                    prof+=d;
                    p=vec[i].first;
                }
            }

            ans=max(ans,prof);


        }
        cout <<"Case #" << j << ": "<< ans << "\n";






    }



    return 0;
}
Editor is loading...
Leave a Comment