알고리즘

[알고리즘] 백준 22864 - 피로도 (C++)

blueberrysoda 2025. 1. 29. 23:57

[문제 링크] : https://www.acmicpc.net/problem/22864

#include <iostream>
using namespace std;

int A, B, C, D;
int Ans, Cnt;

int main(){
    cin >> A >> B >> C >> D;
    int T = 24;
    while(T--){
        if(Cnt + A <= D){ 
            Ans += B;
            Cnt += A;
        }
        else{
            Cnt -= C;
            if(Cnt < 0)
                Cnt = 0;
        }
    }

    cout << Ans << "\n";

    return 0;
}