Codeforces Round #342 (Div. 2) A. Guest from the past (greedy)

Source: Internet
Author: User

Transmission Door

Description

Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as-you-probably know, he found himself in year 2084, and buying kefir there are much more complicated.

Kolya is hungry, so he went to the nearest milk shop. In 2084-buy kefir in a plastic liter bottle, which costs a rubles, or in glass liter bottle s b rubles. Also, you could return empty glass bottle and get C (C < b) rubles back, but you Canno T return plastic bottles.

Kolya has n rubles and he are really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in he 1984, so Kolya doesn ' t know how to act optimally and asks for your help.

Input

First line of the input contains a single integer n (1≤ n ≤10)-the number of rubles Ko Lya has at the beginning.

Then follow three lines containing integers a, b and C (1≤ a ≤10 1≤ C < b ≤10)-the cost of one plastic liter bottle, the cost of one glass lit Er bottle and the money one can get back to returning an empty glass bottle, respectively.

Output

Print the only integer-maximum number of liters of kefir, that Kolya can drink.

Sample Input
10
11
9
8

10
5
6
1
Sample Output
2

2
Ideas

Test instructions

A beverage has two kinds of plastic and glass packaging, buy plastic packaging cost a yuan, buy glass packaging cost B, while glass bottles can be exchanged for C yuan (C < b), plastic packaging can not be exchanged, ask N yuan up to buy how many bottles of drink

Exercises

When B-c < A, buy as much glass packaging as possible, or buy as much plastic packaging as possible.

#include <bits/stdc++.h>using namespace Std;typedef __int64 ll;int main () {LL n,a,b,c,tmp;scanf ("%i64d%i64d%i64d %i64d ", &n,&a,&b,&c); LL cnt = 0; LL d = b-c;if (d < a && n >= b) {n-= B;tmp = n/d;cnt + = tmp;n-= tmp*d; LL dif = n + b;while (dif >= b) {tmp = dif/b;cnt + = tmp;dif-= tmp*b;dif + = Tmp*c;} CNT + = dif/a;} Else{tmp = n/a;cnt + = tmp;n-= tmp*a; LL dif = N;while (dif >= b) {tmp = dif/b;cnt + tmp;dif-= tmp*b;dif + = Tmp*c;}} printf ("%i64d\n", CNT); return 0;}

  

#include <iostream> #include <algorithm>using namespace Std;typedef long Long ll;ll judge (ll N, ll A, ll B, con St ll c) {ll ans = 0;if (B-c < a && n >= b) {ans = (n-b)/(B-C) + 1;n-= (b-c) * ans; Ans + = N/a;return ans;}  int main () {Ios::sync_with_stdio (false); Cin.tie (NULL); ll N, a, B, c;cin >> n;cin >> a >> b >> c;ll Ans = Judge (n, a, b, c); cout << ans << endl;return 0;}

  

Codeforces Round #342 (Div. 2) A. Guest from the past (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.