Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <ctype.h>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <set>
- #include <iostream>
- #include <string>
- #include <queue>
- #include <stack>
- //{{{ ************[ Floating points ]************
- #define ABS(x) (((x) < 0) ? - (x) : (x))
- #define ZERO(x) (ABS (x) < EPS)
- #define EQUAL(x, y) (ZERO ((x) - (y)))
- #define sqr(x) (x*x)
- #define cube(x) (x*x*x)
- #define INF (int)1e9
- #define EPS 1e-9
- #define mset(a,v) memset(a, v, sizeof(a))
- using namespace std;
- typedef long long ll;
- struct choco {
- ll cost;
- bool axis;
- }a [2010];
- int row, col;
- class compare {
- public:
- bool operator () (choco const &a, choco const &b) {
- return a.cost < b.cost;
- }
- };
- priority_queue <choco, vector <choco> , compare> pq;
- int main(){
- int t;
- cin>>t;
- for (int kase = 1; kase <= t; kase++) {
- ll m, n, in = 0;
- cin>>m>>n;
- row = col = 1;
- for (int i = 1; i < m; i++) {
- cin>>a [in].cost;
- a [in++].axis = true;
- }
- for (int i = 1; i < n; i++) {
- cin>>a [in].cost;
- a [in++].axis = false;
- }
- for (int i = 0; i < in; i++) pq.push (a [i]);
- ll total = 0;
- while (!pq.empty ()) {
- ll cost = pq.top ().cost;
- bool axis = pq.top ().axis;
- pq.pop ();
- if (axis) {
- total += cost * col;
- row++;
- }else {
- total += cost * row;
- col++;
- }
- }
- cout<<total<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement