Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Abinash Ghosh(Om)
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- #include <cstring>
- #include <climits>
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <list>
- #include <stack>
- #include <queue>
- #include <map>
- #include <set>
- #include <string>
- #include <utility>
- #include <sstream>
- #include <algorithm>
- using namespace std;
- #define PI acos(-1.0)
- #define MAX 10000007
- #define EPS 1e-9
- #define mem(a,b) memset(a,b,sizeof(a))
- #define gcd(a,b) __gcd(a,b)
- #define pb push_back
- #define mp make_pair
- #define x first
- #define y second
- #define Sort(x) sort(x.begin(),x.end())
- #define FOR(i, b, e) for(int i = b; i <= e; i++)
- #define pr(x) cout<<x<<"\n"
- #define pr2(x,y) cout<<x<<" "<<y<<"\n"
- #define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
- #define READ(f) freopen(f, "r", stdin)
- #define WRITE(f) freopen(f, "w", stdout)
- typedef long long ll;
- typedef pair <int, int> pii;
- typedef pair <double , double> pdd;
- typedef pair <ll , ll > pll;
- typedef vector <int> vi;
- typedef vector <pii> vpii;
- typedef vector <ll > vl;
- //int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
- //int dx[]={1,1,0,-1,-1,-1,0,1};
- //int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
- //int dx[]={2,1,-1,-2,-2,-1,1,2};
- //int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
- ll wait[100005],qt[10004];
- bool cmp(ll a,ll b)
- {
- return a>b;
- }
- struct qp
- {
- ll nxt,tv;
- bool operator<(const qp& p)const
- {
- return nxt >p.nxt;
- }
- };
- int main()
- {
- //READ("in.txt");
- //WRITE("out.txt");
- int T,n,q;
- scanf("%d",&T);
- FOR(t,1,T)
- {
- scanf("%d%d",&n,&q);
- FOR(i,0,n-1)
- scanf("%lld",&wait[i]);
- sort(wait,wait+n,cmp);
- FOR(i,0,q-1)
- scanf("%lld",&qt[i]);
- sort(qt,qt+q);
- priority_queue<qp>Q;
- FOR(i,0,q-1)
- {
- qp a;
- a.nxt=0;
- a.tv=qt[i];
- Q.push(a);
- }
- ll cur , total,ans=-1;
- FOR(i,0,n-1)
- {
- qp temp=Q.top();
- Q.pop();
- cur=temp.nxt+wait[i];
- if(ans<cur)ans=cur;
- temp.nxt=temp.tv+temp.nxt;
- Q.push(temp);
- }
- //Q.clear();
- printf("Case %d: %lld\n",t,ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement