fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, a[300000], b[300000], s, e, rp[300000];
  5. long long rs;
  6.  
  7. int main() {
  8. ios::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. cout.tie(NULL);
  11. cin >> n;
  12. for(int i = 0; i < n; i++)
  13. cin >> a[i];
  14. for(int i = 0; i < n; i++)
  15. cin >> b[i];
  16. sort(b, b + n);
  17. e = n - 1;
  18. for(int i = 1; i < n - 1; i++) {
  19. if(a[i] > a[i - 1] && a[i] > a[i + 1])
  20. rp[i] = b[e--];
  21. if(a[i] < a[i - 1] && a[i] < a[i + 1])
  22. rp[i] = b[s++];
  23. }
  24. if(a[0] > a[1])
  25. rp[0] = b[e--];
  26. else
  27. rp[0] = b[s++];
  28. if(a[n - 1] > a[n - 2])
  29. rp[n - 1] = b[e--];
  30. else
  31. rp[n - 1] = b[s++];
  32. for(int i = 1; i < n - 1; i++) {
  33. if(a[i] < a[i - 1] && a[i] > a[i + 1])
  34. rp[i] = b[e--]
  35. if(a[i] > a[i - 1] && a[i] < a[i + 1])
  36. rp[i] = b[s++];
  37. }
  38. for(int i = 0; i < n - 1; i++)
  39. rs += abs(rp[i] - rp[i + 1]);
  40. cout << rs << "\n";
  41. for(int i = 0; i < n; i++)
  42. cout << rp[i] << ' ';
  43. return 0;
  44. }
Compilation error #stdin compilation error #stdout 0s 4512KB
stdin
4
5 7 4 9
1 2 3 4
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:34:18: error: expected ‘;’ before ‘if’
    rp[i] = b[e--]
                  ^
                  ;
   if(a[i] > a[i - 1] && a[i] < a[i + 1])
   ~~              
stdout
Standard output is empty