Cod sursă (job #465523)

Utilizator avatar avramdaniel Beefichor avramdaniel IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 0,68 kb
Rundă Arhiva de probleme Status evaluat
Dată 2 apr. 2019 19:54:23 Scor 100
#include <bits/stdc++.h>
using namespace std;

int c,t,m,x,nr,tot,ans;

int main()
{
    ifstream cin("scv.in");
    ofstream cout("scv.out");
    cin>>c>>t>>m>>x;
    nr = 1;
    tot = 0;
    while(tot < x)
    {
        while(tot<x && tot<c)
        {
            ans++;
            tot+=m*nr;
        }
        if(tot>=x) break;

        if(tot + nr*m*t < x - m*nr*(c/m))
        {
            ans+=t;
            tot-=c;
            tot+=nr*m*t;
            nr++;
        }
        else
        {
            while(tot<x)
            {
                ans++;
                tot+=m*nr;
            }
        }
    }
    cout<<ans;

    return 0;
}