Saleh127

CF 1399B

Aug 6th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);cout.tie(0);
  7.  
  8. int t;
  9. cin>>t;
  10. while(t--)
  11. {
  12. long long a[10000],c[10000],d,e=0,f=0,i,j=0,k,l,m=100000000000,n=100000000000;
  13. cin>>d;
  14. for(i=0;i<d;i++)
  15. {
  16. cin>>a[i];
  17. m=min(m,a[i]);
  18. }
  19. for(i=0;i<d;i++)
  20. {
  21. cin>>c[i];
  22. n=min(n,c[i]);
  23. }
  24. for(i=0;i<d;i++)
  25. {
  26. if(a[i]!=m && c[i]!=n)
  27. {
  28. e=a[i]-m;
  29. f=c[i]-n;
  30. j+=max(e,f);
  31. }
  32. else
  33. {
  34. e=a[i]-m;
  35. f=c[i]-n;
  36. j+=(e+f);
  37. }
  38. }
  39. cout<<j<<endl;
  40. }
  41. return 0;
  42. }
  43.  
Add Comment
Please, Sign In to add comment