diff --git a/2020/Div 3/661 Div 3/Programs/Gifts Fixing.cpp b/2020/Div 3/661 Div 3/Programs/Gifts Fixing.cpp index fa6a0be5..6a23db45 100644 --- a/2020/Div 3/661 Div 3/Programs/Gifts Fixing.cpp +++ b/2020/Div 3/661 Div 3/Programs/Gifts Fixing.cpp @@ -1,54 +1,54 @@ -#include -#include -#include - -#define all(v) (v).begin(), (v).end() +#include +#include +#define lli long long int +#define pb push_back +#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) +#define rep(i,a,n) for(i=a;i> no_of_elements; - - vector A(no_of_elements + 1); - for(int i = 1; i <= no_of_elements; i++) - { - cin >> A[i]; - } - - vector B(no_of_elements + 1); - for(int i = 1; i <= no_of_elements; i++) - { - cin >> B[i]; - } - - const int oo = 1e9 + 9; - int target_A = oo, target_B = oo; - - for(int i = 1; i <= no_of_elements; i++) - { - target_A = min(target_A, A[i]); - target_B = min(target_B, B[i]); - } - - long long no_of_moves = 0; - for(int i = 1; i <= no_of_elements; i++) - { - long long a_moves_here = A[i] - target_A, b_moves_here = B[i] - target_B; - - no_of_moves += max(a_moves_here, b_moves_here); - } - - cout << no_of_moves << "\n"; -} - int main() { - int no_of_test_cases; - cin >> no_of_test_cases; - - while(no_of_test_cases--) - solve(); - - return 0; + cio; + lli t,n,i,ma,mb,k,ans=0; + cin>>t; + while(t--){ + cin>>n; + ma=1e18; + mb=1e18; + ans=0; + lli a[n],b[n]; + for(i=0;i>a[i]; + ma=min(ma,a[i]); + } + for(i=0;i>b[i]; + mb=min(mb,b[i]); + } + for(i=0;ima&&b[i]>mb){ + k=min(a[i]-ma,b[i]-mb); + ans+=k; + a[i]=a[i]-k; + b[i]=b[i]-k; + } + else if(a[i]>ma){ + k=a[i]-ma; + ans+=k; + a[i]=ma; + } + else if(b[i]>mb){ + k=b[i]-mb; + ans+=k; + b[i]=mb; + } + } + } + cout<