-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSA03007 - GIÁ TRỊ NHỎ NHẤT CỦA BIỂU THỨC
92 lines (92 loc) · 1.82 KB
/
DSA03007 - GIÁ TRỊ NHỎ NHẤT CỦA BIỂU THỨC
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//Made By Phuong Nam PROPTIT <3//
#pragma GCC Optimize("O3")
#include<bits/stdc++.h>
#include<string>
#include<vector>
#define alphaa "abcdefghijklmnopqrstuvwxyz"
#define ALPHAA "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define f(i,a,b) for(int i=a;i<=b;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f0(i,n) for(int i=0;i<n;i++)
#define ff(i,b,a) for(int i=b;i>=a;i--)
#define el cout<<'\n'
#define fi first
#define se second
#define pb push_back
#define pk pop_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(s) s.begin(),s.end()
using namespace std;
typedef long long ll;
const int N=1e6+3;
const int MOD=1e9+7;
template<class X,class Y>
void minimize(X &x,const Y &y) {
if (x>y) x=y;
}
template<class X,class Y>
void maximize(X &x,const Y &y) {
if (x<y) x=y;
}
template<class T>
T Abs(const T &x) {
return (x<0?-x:x);
}
ll tinh1(ll a[],ll b[],int n)
{
sort(a,a+n);
sort(b,b+n);
ll s=0;
f0(i,n) s+=a[i]*b[i];
return s;
}
ll tinh2(ll a[],ll b[],int n)
{
sort(a,a+n);
sort(b,b+n,greater<ll>());
ll s=0;
f0(i,n) s+=a[i]*b[i];
return s;
}
ll tinh3(ll a[],ll b[],int n)
{
sort(a,a+n,greater<ll>());
sort(b,b+n);
ll s=0;
f0(i,n) s+=a[i]*b[i];
return s;
}
ll tinh4(ll a[],ll b[],int n)
{
sort(a,a+n,greater<ll>());
sort(b,b+n,greater<ll>());
ll s=0;
f0(i,n) s+=a[i]*b[i];
return s;
}
void xuly()
{
int n;
cin>>n;
ll a[n],b[n];
f0(i,n) cin>>a[i];
f0(i,n) cin>>b[i];
ll t1=tinh1(a,b,n);
ll t2=tinh2(a,b,n);
ll t3=tinh3(a,b,n);
ll t4=tinh4(a,b,n);
cout<<min(min(t1,t2),min(t2,t3));
el;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--) xuly();
return 0;
}
//-----YEU CODE HON CRUSH-----//