-
Notifications
You must be signed in to change notification settings - Fork 3
/
CHOCOLA.cpp
56 lines (52 loc) · 816 Bytes
/
CHOCOLA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* CHOCOLA.cpp
*
* Created on: Mar 18, 2015
* Author: ngoyal
*/
#include<iostream>
#include<algorithm>
#define MAX 1009
using namespace std;
int main(){
int m,n;
int x[MAX],y[MAX];
int T;
cin >> T;
// cin>> x[1];
for(int i=0;i<T;i++){
cin >> m>> n;
m--;n--;
for(int j=0;j<m;j++){
cin>>x[j];
}
for(int j=0;j<n;j++){
cin>>y[j];
}
sort(x,x+m,greater<int>());
sort(y,y+n,greater<int>());
int result;
int rows=1,cols=1;
int cur_x=0,cur_y=0;
while(cur_x!=m&&cur_y!=n){
if(x[cur_x]>y[cur_y]){
result+=x[cur_x]*cols;
rows++;
cur_x++;
}else{
result+=y[cur_y]*rows;
cols++;
cur_y++;
}
}
while(cur_x!=m){
result+=x[cur_x]*cols;
cur_x++;
}
while(cur_y!=n){
result+=y[cur_y]*rows;
cur_y++;
}
cout << result <<"\n";
}
}