Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- vector<int> a(n), b(m);
- int wys_1 = 0, wys_2 = 0;
- for (int i = 0; i < n; ++i)
- {
- cin >> a[i];
- wys_1 += a[i];
- }
- for (int i = 0; i < m; ++i)
- {
- cin >> b[i];
- wys_2 += b[i];
- }
- int answ = 0;
- if (wys_1 == wys_2)
- {
- cout << "0";
- return 0;
- }
- int i = n - 1, j = m - 1;
- while (wys_1 != wys_2)
- {
- if (wys_1 > wys_2)
- {
- while (wys_1 != wys_2)
- {
- wys_1 - a[i];
- answ++;
- if (wys_1 != wys_2)
- {
- wys_2 - b[j];
- answ++;
- }
- }
- }
- if (wys_2 > wys_1)
- {
- while (wys_1 != wys_2)
- {
- wys_2 - b[j];
- answ++;
- if (wys_1 != wys_2)
- {
- wys_1 - a[i];
- answ++;
- }
- }
- }
- if (i >= 0)
- --i;
- if (j >= 0)
- --j;
- }
- cout << answ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement