Advertisement
mickypinata

TOI15: Medal

Nov 7th, 2021
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long lli;
  5.  
  6. const int N = 5e5;
  7.  
  8. lli people[N + 1], stage[N + 1];
  9. int nSeq;
  10.  
  11. int main(){
  12.  
  13.     scanf("%d", &nSeq);
  14.     for(int i = 1; i <= nSeq; ++i){
  15.         scanf("%lld", &people[i]);
  16.     }
  17.     for(int i = 1; i <= nSeq; ++i){
  18.         scanf("%lld", &stage[i]);
  19.     }
  20.     sort(people + 1, people + nSeq + 1);
  21.     sort(stage + 1, stage + nSeq + 1, greater<lli>());
  22.     for(int i = 1; i <= nSeq; ++i){
  23.         stage[i] += people[i];
  24.     }
  25.     sort(stage + 1, stage + nSeq + 1);
  26.     lli sum = 0;
  27.     for(int i = 1; i < nSeq; ++i){
  28.         sum += stage[i + 1] - stage[i];
  29.     }
  30.     cout << sum;
  31.  
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement