Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <ctype.h>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <map>
  9. #include <set>
  10. #include <iostream>
  11. #include <string>
  12. #include <queue>
  13. #include <stack>
  14.  
  15. //{{{ ************[  Floating points     ]************
  16. #define ABS(x)          (((x) < 0) ? - (x) : (x))
  17. #define ZERO(x)         (ABS (x) < EPS)
  18. #define EQUAL(x, y)     (ZERO ((x) - (y)))
  19.  
  20. #define sqr(x)        (x*x)
  21. #define cube(x)        (x*x*x)
  22. #define INF            (int)1e9
  23. #define EPS            1e-9
  24.  
  25. #define mset(a,v)    memset(a, v, sizeof(a))
  26.  
  27. using namespace std;
  28. typedef long long ll;
  29.  
  30. struct choco {
  31.     ll cost;
  32.     bool axis;
  33. }a [2010];
  34.  
  35. int row, col;
  36.  
  37. class compare {
  38.     public:
  39.     bool operator () (choco const &a, choco const &b) {
  40.         return a.cost < b.cost;
  41.     }
  42. };
  43.  
  44. priority_queue <choco, vector <choco> , compare> pq;
  45.  
  46. int main(){
  47.     int t;
  48.     cin>>t;
  49.  
  50.     for (int kase = 1; kase <= t; kase++) {
  51.         ll m, n, in = 0;
  52.         cin>>m>>n;
  53.         row = col = 1;
  54.         for (int i = 1; i < m; i++) {
  55.             cin>>a [in].cost;
  56.             a [in++].axis = true;
  57.         }
  58.  
  59.         for (int i = 1; i < n; i++) {
  60.             cin>>a [in].cost;
  61.             a [in++].axis = false;
  62.         }
  63.         for (int i = 0; i < in; i++) pq.push (a [i]);
  64.  
  65.         ll total = 0;
  66.         while (!pq.empty ()) {
  67.             ll cost = pq.top ().cost;
  68.             bool axis = pq.top ().axis;
  69.             pq.pop ();
  70.  
  71.             if (axis) {
  72.                 total += cost * col;
  73.                 row++;
  74.             }else {
  75.                 total += cost * row;
  76.                 col++;
  77.             }
  78.         }
  79.         cout<<total<<endl;
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement