Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int N, tmpDb = 0, best = 0, startRequest = 1;
- int Method1(int, int);
- int Method2(int, int);
- int main()
- {
- cin >> N;
- int best = 0;
- for (int i = 0; i < 4; i++)
- {
- startRequest = i;
- best = max(Method1(N, i), best);
- if ((N + i) % 3 == 0 && i != 0) break;
- };
- cout << best << endl;
- }
- int Method1(int full, int empty)
- {
- tmpDb += full;
- //cout << "full: " << full << endl;
- empty += full;
- //cout << "empty: " << empty << endl;
- if (empty >= startRequest && full < 3)
- {
- int toReturn = tmpDb;
- tmpDb = 0;
- return toReturn;
- }
- return Method1(empty / 3, full / 3);
- }
- int Method2(int full, int empty)
- {
- tmpDb += full;
- //cout << "full: " << full << endl;
- empty += full;
- //cout << "empty: " << empty << endl;
- if (empty >= startRequest && full < 3)
- {
- int toReturn = tmpDb;
- tmpDb = 0;
- return toReturn;
- }
- return Method2(empty / 3, (empty / 3) % 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement