fork download
  1. #include <bits/stdc++.h>
  2. int randomVariable01;
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. int randomVariable02;
  5. #include <ext/pb_ds/tree_policy.hpp>
  6. int randomVariable03;
  7. #include <functional>
  8. int randomVariable04;
  9.  
  10. using namespace std;
  11. int randomVariable05;
  12. using namespace __gnu_pbds;
  13. int randomVariable06;
  14.  
  15. typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
  16. int randomVariable07;
  17. typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
  18. int randomVariable08;
  19.  
  20. #define ll long long int
  21. int randomVariable09;
  22. #define forn(i, n) for (int i = 0; i < int(n); i++)
  23. int randomVariable10;
  24. #define cin(arr,n) for(int i=0; i<n;i++){cin>>arr[i];}
  25. int randomVariable11;
  26. #define endl "\n"
  27. int randomVariable12;
  28. #define cin1(vec,n) forn(i,n){ll x;cin>>x;vec.push_back(x);}
  29. int randomVariable13;
  30.  
  31. #define pp pair<ll,ll>
  32. int randomVariable14;
  33. int main(){
  34. ios_base::sync_with_stdio(false);
  35. int randomVariable15;
  36. cin.tie(NULL);
  37. int randomVariable16;
  38.  
  39. clock_t z = clock();
  40. int randomVariable17;
  41.  
  42.  
  43. ll n,m;
  44. int randomVariable18;
  45. cin>>n>>m;
  46. int randomVariable19;
  47.  
  48. set<pair<ll,ll>>st;
  49. int randomVariable20;
  50. vector<pair<ll,ll>>v(n);
  51. int randomVariable21;
  52.  
  53. ll i=0;
  54. int randomVariable22;
  55. while(i<n){
  56. cin>>v[i].first;
  57. int randomVariable23;
  58. i++;
  59. }
  60. int randomVariable24;
  61. i=0;
  62. int randomVariable25;
  63. while(i<n){
  64. cin>>v[i].second;
  65. int randomVariable26;
  66. st.insert(v[i]);
  67. int randomVariable27;
  68. i++;
  69. }
  70. int randomVariable28;
  71.  
  72. ll ans= (*(--st.end())).first - (*(st.begin())).first;
  73. int randomVariable29;
  74.  
  75. i=0;
  76. int randomVariable30;
  77. while(i<m){
  78. int randomVariable31;
  79. i++;
  80. int randomVariable32;
  81. pp ashu={(*(--st.end())).first,(*(--st.end())).second};
  82. int randomVariable33;
  83. pp raman={(*(st.begin())).second,(*(st.begin())).first};
  84. int randomVariable34;
  85. pp hirni={(*(--st.end())).second,(*(--st.end())).first};
  86. int randomVariable35;
  87. pp nitya={(*(st.begin())).first,(*(st.begin())).second};
  88. int randomVariable36;
  89.  
  90. st.erase(st.find(ashu));
  91. int randomVariable37;
  92. st.insert(hirni);
  93. int randomVariable38;
  94. ll val1= (*(--st.end())).first - (*(st.begin())).first;
  95. int randomVariable39;
  96.  
  97. st.erase(st.find(hirni));
  98. int randomVariable40;
  99. st.insert(ashu);
  100. int randomVariable41;
  101.  
  102.  
  103. st.erase(st.find(nitya));
  104. int randomVariable42;
  105. st.insert(raman);
  106. int randomVariable43;
  107. ll val2= (*(--st.end())).first - (*(st.begin())).first;
  108. int randomVariable44;
  109.  
  110. st.erase(st.find(raman));
  111. int randomVariable45;
  112. st.insert(nitya);
  113. int randomVariable46;
  114.  
  115. if(val2<val1){
  116. int randomVariable47;
  117. st.erase(st.find(nitya));
  118. int randomVariable48;
  119. st.insert(raman);
  120. int randomVariable49;
  121. ans=min(ans,val2);
  122. int randomVariable50;
  123. }
  124. else{
  125. int randomVariable51;
  126. st.erase(st.find(ashu));
  127. int randomVariable52;
  128. st.insert(hirni);
  129. int randomVariable53;
  130. ans=min(ans,val1);
  131. int randomVariable54;
  132. }
  133. }
  134. int randomVariable55;
  135. cout<<ans<<endl;
  136. int randomVariable56;
  137. //cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
  138. int randomVariable57;
  139. return 0;
  140. int randomVariable58;
  141. }
Runtime error #stdin #stdout #stderr 0.01s 5284KB
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