Advertisement
smatskevich

Solutions2

Jan 8th, 2022
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <map>
  4. #include <set>
  5. #include <string>
  6. #include <tuple>
  7. #include <unordered_map>
  8. #include <unordered_set>
  9. #include <vector>
  10.  
  11. typedef long long ll;
  12. using namespace std;
  13.  
  14. int main1() {
  15.   ios::sync_with_stdio(false);
  16.   cin.tie(nullptr);
  17.  
  18.   int n = 0;
  19.   cin >> n;
  20.  
  21.   vector<int> a(n);
  22.   for (int i = 0; i < n; ++i) cin >> a[i];
  23.   vector<int> b(n);
  24.   for (int i = 0; i < n; ++i) cin >> b[i];
  25.  
  26.   int amax_index = 0;
  27.   int max_sum = a[0] + b[0];
  28.   int result_i = 0, result_j = 0;
  29.   for (int k = 1; k < n; ++k) {
  30.     if (a[k] > a[amax_index]) amax_index = k;
  31.     if (b[k] + a[amax_index] > max_sum) {
  32.       result_i = amax_index;
  33.       result_j = k;
  34.     }
  35.   }
  36.   cout << result_i << " " << result_j;
  37.  
  38.   return 0;
  39. }
  40.  
  41. int main2() {
  42.   ios::sync_with_stdio(false);
  43.   cin.tie(nullptr);
  44.  
  45.   int n = 0;
  46.   cin >> n;
  47.   vector<int> a(n);
  48.   for (int i = 0; i < n; ++i) cin >> a[i];
  49.   int m = 0;
  50.   cin >> m;
  51.   vector<int> b(m);
  52.   for (int i = 0; i < m; ++i) cin >> b[i];
  53.  
  54.   for (int x : b) {
  55.     auto pos = lower_bound(a.begin(), a.end(), x);
  56.     if (pos == a.begin()) cout << 0 << " ";
  57.     else if (pos == a.end()) cout << a.size() - 1 << " ";
  58.     else {
  59.       // Проверить элемент *pos и *(pos - 1)
  60.     }
  61.   }
  62.  
  63.   return 0;
  64. }
  65.  
  66.  
  67. int main() {
  68.   ios::sync_with_stdio(false);
  69.   cin.tie(nullptr);
  70.  
  71.   int n = 0;
  72.   cin >> n;
  73.   vector<pair<int, int>> c(n);
  74.   for (int i = 0; i < n; ++i) {
  75.     cin >> c[i].first;
  76.     c[i].second = i;
  77.   }
  78.   sort(c.begin(), c.end());
  79.  
  80.   // Выводим исходные индексы
  81.   for (auto& p : c) {
  82.     cout << p.second << " ";
  83.   }
  84.  
  85.   return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement