fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <iomanip>
  14. #define dibs reserve
  15. #define OVER9000 1234567890
  16. #define patkan 9
  17. #define tisic 47
  18. #define soclose 1e-9
  19. #define pi 3.1415926535898
  20. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  21. #define chocolate win
  22. #define ff first
  23. #define ss second
  24. #define abs(x) ((x < 0)?-(x):(x))
  25. #define uint unsigned int
  26. #include <time.h>
  27. // mylittlepony
  28. using namespace std;
  29.  
  30. int main() {
  31. cin.sync_with_stdio(0);
  32. int N;
  33. cin >> N;
  34. vector<long long> R(N),S(N);
  35. for(int i =0; i < N; i++) cin >> R[i];
  36. for(int i =0; i < N; i++) cin >> S[i];
  37.  
  38. vector< pair<long long,long long> > A(2*N);
  39. for(int i =0; i < N/2; i++) A[i].ff =R[i]-(N/2-i), A[i].ss =R[i];
  40. for(int i =N/2; i < N; i++) A[i].ff =R[i]-(i-N/2), A[i].ss =R[i];
  41. for(int i =0; i < N/2; i++) A[i+N].ff =S[i]-(N/2-i), A[i+N].ss =S[i];
  42. for(int i =N/2; i < N; i++) A[i+N].ff =S[i]-(i-N/2), A[i+N].ss =S[i];
  43. sort(A.begin(),A.end());
  44.  
  45. if(A[N].ff > 0) {
  46. long long x =A[N].ff;
  47. for(int i =0; i < 2*N; i++) A[i].ff -=x;}
  48.  
  49. long long x =0;
  50. for(int i =0; i < 2*N; i++) x =max(x,A[i].ff-A[i].ss);
  51. for(int i =0; i < 2*N; i++) A[i].ff -=x;
  52.  
  53. long long ans =0;
  54. for(int i =0; i < 2*N; i++) ans +=abs(A[i].ff);
  55. cout << ans << "\n";
  56. return 0;}
  57.  
  58. // look at my code
  59. // my code is amazing
Runtime error #stdin #stdout #stderr 0s 4460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc