Codeforces 651A Joysticks Greedy

Source: Internet
Author: User

A. joystickstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Friends is going to play console. They has joysticks and only one charger for them. Initially first joystick is charged at a1 Percent and second one is charged at a2 Percent. You can connect charger to a joystick only at the beginning for each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connecte D to a charger).

Game continues while both joysticks has a positive charge. Hence, if at the beginning of minute some joystick was charged by 1 percent, it have to being connected to a charger, otherwise The game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.

Determine the maximum number of minutes that game can last. It is prohibited to pause the game, I e. at each moment both joysticks should are enabled. It's allowed for joystick to being charged by more than percent.

Input

The first line of the input contains the positive integers a1 and a2 (1≤ a1, a2 ≤100), the initial charge level of first and second joystick respectively.

Output

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

Examplesinput
3 5
Output
6
Input
4 4
Output
5
The main topic: There are two handles, we will give him the remaining power, each charge a minute will be more than 1% of the power, not charging will drop 2% of the electricity.
Idea: greedy, priority to choose the charge of less power, note two handle charge is 1 o'clock special circumstances

#include <stdio.h>intMain () {intA, B, t=0; scanf ("%d%d", &a, &b);  while(a>=1&&b>=1)    {        if(a==1&&b==1)         Break; if(a>b) {a-=2; b++; T++; }        Else{b-=2; A++; T++; }} printf ("%d\n", T); return 0;}

Codeforces 651A Joysticks Greedy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.