Cod sursă (job #294416)

Utilizator avatar micutu Andrei Vasile Cont Fraudulent micutu IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 0,63 kb
Rundă Arhiva de probleme Status evaluat
Dată 19 mar. 2017 21:46:39 Scor 100
#include <cstdio>

using namespace std;

int main()
{
    FILE *fin, *fout;
    long long c, t, m, x, ans, prodz, tot;
    fin=fopen("scv.in", "r");
    fscanf(fin, "%lld%lld%lld%lld", &c, &t, &m, &x);
    fclose(fin);
    ans=tot=0LL; prodz=m;
    while(tot<x){
      while(tot<x && tot<c){
        ans++;
        tot+=prodz;
      }
      if(tot+prodz*t+prodz*(c/m)<x){
        ans+=t;
        tot+=prodz*t-c;
        prodz+=m;
      } else
        while(tot<x){
          ++ans;
          tot+=prodz;
        }
    }
    fout=fopen("scv.out", "w");
    fprintf(fout, "%lld\n", ans);
    fclose(fout);
    return 0;
}