Guest User

Untitled

a guest
Sep 20th, 2021
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Natus Vincere
  2. Born To Conquer */
  3.  
  4. #include <bits/stdc++.h>
  5. #define ll long long int
  6. #define pi 3.1415926535897932385
  7. #define mod 1000000007
  8. #define db double
  9. #define pp(x) pair<x,x>
  10. #define ff first
  11. #define ss second
  12. #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
  13. #define tc ll tc; cin>>tc ; cin.ignore(5,'\n'); for(ll number = 1 ; number <= tc ; number ++ )
  14. #define vv(x) vector<x >
  15. #define pb push_back
  16. #define pob pop_back
  17. #define pf push_front
  18. #define pof pop_front
  19. #define endl "\n"
  20. #define umap unordered_map
  21. #define pq priority_queue
  22. #define dbg(x) { cout<< #x << ": " << (x) << endl; }
  23. #define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
  24. #define bp ll kkk; cin >>kkk;
  25. #define dbgArr(a,n) cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
  26. #define forn(i,n) for(ll i=0 ; i<n ; i++)
  27. #define forn1(i,n) for(ll i=1 ; i<=n ; i++)
  28. #define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
  29. #define arr1(a,n) for(ll i=1;i<=n;i++){ cin>>a[i]; }
  30. #define file freopen("inp.in","r",stdin); freopen("outp.out","w",stdout)
  31. #define print cout<<"Case #"<<number<<": "
  32. #define all(x) x.begin(), x.end()
  33. #define trav(x, a) for(auto &x: a)
  34. #define inf 1e18 ;
  35.  
  36. using namespace std ;
  37.  
  38. ll query(vector<ll> v , ll ts)
  39. {
  40. ll x,y ; cin>>x>>y ;
  41. ll minc=0 ;
  42. ll idx=lower_bound(all(v),x)-v.begin();
  43.  
  44. ll a ;
  45.  
  46. if(idx==v.size())
  47. {
  48. idx-- ;
  49. a=v[idx];
  50. minc=max(0LL,x-a)+max(0LL,y-ts+a);
  51. return minc ;
  52. }
  53.  
  54. a=v[idx];
  55. minc=max(0LL,x-a)+max(0LL,y-ts+a);
  56.  
  57. a=v[idx+1];
  58. minc=min(minc , max(0LL,x-a)+max(0LL,y-ts+a));
  59. return minc ;
  60. }
  61.  
  62. int main()
  63. {
  64. FIO
  65. ll n ; cin>>n ;
  66. vector<ll> v(n) ; arr(v,n); sort(all(v));
  67. ll ts=accumulate(v.begin(),v.end(),0);
  68. tc cout<<query(v,ts)<<endl;
  69. return 0 ;
  70. }
  71.  
RAW Paste Data