Advertisement
Augenbrauen

Dwie wieże, to mi śmierdzi Tolkienem

Oct 9th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, m;
  9.     cin >> n >> m;
  10.     vector<int> a(n), b(m);
  11.     int wys_1 = 0, wys_2 = 0;
  12.     for (int i = 0; i < n; ++i)
  13.     {
  14.         cin >> a[i];
  15.         wys_1 += a[i];
  16.     }
  17.     for (int i = 0; i < m; ++i)
  18.     {
  19.         cin >> b[i];
  20.         wys_2 += b[i];
  21.     }
  22.     int answ = 0;
  23.     if (wys_1 == wys_2)
  24.     {
  25.         cout << "0";
  26.         return 0;
  27.     }
  28.     int i = n - 1, j = m - 1;
  29.     while (wys_1 != wys_2)
  30.     {
  31.         if (wys_1 > wys_2)
  32.         {
  33.             while (wys_1 != wys_2)
  34.             {
  35.                 wys_1 - a[i];
  36.                 answ++;
  37.                 if (wys_1 != wys_2)
  38.                 {
  39.                     wys_2 - b[j];
  40.                     answ++;
  41.                 }
  42.             }
  43.         }
  44.         if (wys_2 > wys_1)
  45.         {
  46.             while (wys_1 != wys_2)
  47.             {
  48.                 wys_2 - b[j];
  49.                 answ++;
  50.                 if (wys_1 != wys_2)
  51.                 {
  52.                     wys_1 - a[i];
  53.                     answ++;
  54.                 }
  55.             }
  56.         }
  57.         if (i >= 0)
  58.         --i;
  59.         if (j >= 0)
  60.         --j;
  61.     }
  62.     cout << answ;
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement