Korotkodul

итмо 8

Feb 15th, 2022 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33. for (bool x: v) cout<<x<<' ';
  34. cout<<"\n";
  35. }
  36.  
  37. bool cmp(pii a, pii b){
  38. return a.second < b.second || a.second == b.second && a.first > b.first;
  39. }
  40.  
  41.  
  42. int main()
  43. {
  44. /*ios::sync_with_stdio(0);
  45. cin.tie(0);
  46. cout.tie(0);*/
  47. int n,k;
  48. cin>>n>>k;
  49. vector <int> x(n); for (int &i: x) cin>>i;
  50. sort(x.begin(), x.end());
  51. vector <int> a(n,0), b(n,0);
  52. for (int i = 1; i < n; ++i){
  53. a[i] = a[i-1] + abs(x[i] - x[i-1]);
  54. }
  55. for (int i = n - 2; i >= 0; --i){
  56. b[i] = b[i + 1] + abs(x[i] - x[i+1]);
  57. }
  58. vector <int> c(n);
  59. for (int i = 0; i < n;++i){
  60. c[i] = a[i] + b[i];
  61. }
  62. vector <int> res;
  63. for (int i = )
  64. vector <pii> d(n);
  65. for (int i = 0; i < n;++i){
  66. d[i] = {x[i], c[i]};
  67. }
  68. cout<<"x\n";
  69. cv(x);
  70. cout<<"a\n";
  71. cv(a);
  72. cout<<"b\n";
  73. cv(b);
  74. cout<<"c\n";
  75. cv(c);
  76. sort(d.begin(), d.end(), cmp);
  77. cout<<d[0].first<<' '<<d[0].second;
  78. }
  79.  
Add Comment
Please, Sign In to add comment