-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_00434.cpp
65 lines (62 loc) · 1.39 KB
/
prob_00434.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
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <bitset>
#define repf(i,start,end) for(i=start;i<end;++i)
#define repb(i,start,end) for(i=end;i>=start;i--)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define gc getchar_unlocked
#define size 10
using namespace std;
int max(int a, int b){return a>b?a:b;}
int min(int a, int b){return a>b?b:a;}
void swap(int& a,int &b){int temp= a; a=b; b=temp;}
int getMin(int* front, int *side, int n){
bool marked_f[size]={false};
bool marked_s[size]={false};
int i,j,k;
int result=0;
repf(i,0,n){
repf(j,0,n){
if(!marked_f[i] && !marked_s[j] && front[i]==side[j]){
result+= front[i];
marked_f[i]=marked_s[j]=true;
}
}
}
repf(i,0,n){
if(!marked_f[i]) result+=front[i];
if(!marked_s[i]) result+=side[i];
}
return result;
}
int main(){
int t,n,i,j,k;
int front[size],side[size];
si(t);
while(t--){
si(n);
repf(i,0,n) si(front[i]);
repf(i,0,n) si(side[i]);
int front_sum=0, side_sum=0;
repf(i,0,n){
front_sum+=front[i];
side_sum+=side[i];
}
front_sum=getMin(front,side,n);
side_sum=0;
repf(i,0,n){
repf(j,0,n)
side_sum+=min(front[i],side[j]);
}
printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n",
front_sum,side_sum-front_sum);
}
}