Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Question
- Brain Station-23 has a Robot! This Robot has a very special food habit. Dependending on a day of the week, It eats certain type of food:
- on Monday, Thursday and Sunday It eats black circuit boards;
- on Tuesday and Saturday It eats red circuit boards;
- on other days of week he eats green circuit boards.
- BS-23 plans to go on an annual trip. This Robot takes a backpack which contains:
- a daily rations of black circuit boards;
- b daily rations of red circuit boards;
- c daily rations of green circuit boards.
- BS-23 has to select such a day of the week to start that there robot can eat without additional food purchases as long as possible. If Bs-23 chooses the day of the week to start optimally, help them to find the maximum number of days the Robot can eat in a trip without additional food purchases.
- Input
- The first line of the input contains three positive integers a, b and c — the number of daily rations of black circuit boards, red circuit boards and green circuit boards in Robot's backpack correspondingly.
- 1 ≤ a,b,c ≤7 * 108
- Output
- Print the maximum number of days the Robot can eat in a trip without additional food purchases, if BS-23 chooses the day of the week to start his trip optimally.
- Examples
- Input
- 2 1 1
- Output
- 4
- Input
- 3 2 2
- Output
- 7
- Input
- 1 100 1
- Output
- 3
- Input
- 30 20 10
- Output
- 39
- Note
- In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the robot will eat black circuit board, during Tuesday — red circuit board and during Wednesday — green circuit board. So, after four days of the trip all food will be eaten.
- /*
- #include <bits/stdc++.h>
- using namespace std;
- /*
- Complexity: O(log n)
- Idea: Binary search on number of day we can plan for trip.
- And check if it is possible of not to trip for this many day if we start from all 7 days.
- */
- long long x,y,z;
- bool check(long long now)
- {
- long long week = now/7;
- bool flag = false;
- for(int i=0;i<7;i++)
- {
- long long b = x - week * 3, r = y - week * 2, g = z - week * 2;
- int idx = i;
- int remDay = now%7;
- while(remDay--){
- if(idx==0) r--;
- else if(idx==1) b--;
- else if(idx==2) b--;
- else if(idx==3) r--;
- else if(idx==4) g--;
- else if(idx==5) b--;
- else g--;
- idx = (idx+1)%7;
- }
- if(b>=0 and r>=0 and g>=0) flag = true;
- }
- return flag;
- }
- int main()
- {
- cin >> x >> y >> z;
- long long lo = 0, hi = 1e18, ans = -1;
- while(lo<=hi)
- {
- long long mid = (lo+hi)/2;
- if(check(mid)){
- ans = mid;
- lo = mid + 1;
- }
- else hi = mid - 1;
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement