Advertisement
smatskevich

Seminar1

Jan 7th, 2022
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 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. // |-----|-2---|-----0-----|-2---|
  15. // -5 3 -> 1
  16. int main1() {
  17.   int a, b;
  18.   cin >> a >> b;
  19.   int r = a % b;
  20.   if (r < 0) r += abs(b);
  21.   cout << r << endl;
  22.  
  23.   return 0;
  24. }
  25.  
  26. int main2() {
  27.   int n = 0;
  28.   cin >> n;
  29.  
  30.   // Считываем первое.
  31.   int a = 0;
  32.   cin >> a;
  33.   int min_value = a;
  34.   int min_index = 0;
  35.   int max_value = a;
  36.   int max_index = 0;
  37.  
  38.   // Считываем остальные.
  39.   for (int i = 1; i < n; i++) {
  40.     cin >> a;
  41.     if (a <= min_value) {
  42.       min_value = a;
  43.       min_index = i;
  44.     }
  45.     if (a >= max_value) {
  46.       max_value = a;
  47.       max_index = i;
  48.     }
  49.   }
  50.   cout << min_index << " " << max_index << endl;
  51.   return 0;
  52. }
  53.  
  54. /*
  55. -----------------------b
  56. |                      |
  57. |                      |
  58. a-----------------------
  59.  
  60. --------a
  61. |       |
  62. |       |
  63. a--------
  64. */
  65. int main() {
  66.   int a = 0, b = 0, k = 0;
  67.   cin >> a >> b >> k;
  68.   if (a > b) swap(a, b);
  69.  
  70.   if (b - a >= k) {
  71.     b -= k;
  72.   } else {
  73.     k -= b - a;
  74.     b = a - (k / 2 + k % 2);
  75.     a = a - k / 2;
  76.   }
  77.   cout << a << " " << b << endl;
  78.   return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement