본문 바로가기

Competition/codeforces

Educational Codeforces Round 52 (Rated for Div. 2) A. Vasya and Chocolate

A. Vasya and Chocolate

https://codeforces.com/problemset/problem/1065/A


a개를 사면 b개가 꽁짜!

가격이 c원이고, s원을 가지고 있을 때, 최대로 살 수 있는 초콜릿의 개수를 구하면 된다.

처음 더해주는 것은 정확히 a개씩 몇개 살 수 있는지 구하고, 증정품까지 더해서 살 수 있는 최대 개수

다음으로 더해주는 것은 증정품 필요 없이 그냥 남은거 살 수 있는 만큼 사는 개수


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
 
int t;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> t;
    while (t--) {
        long long s, a, b, c, ans = 0;
        cin >> s >> a >> b >> c;
        ans += (s / c) / a * (a + b);
        ans += (s / c) % a;
        cout << ans << '\n';
    }
    return 0;
}
cs