Cod sursă (job #108354)

Utilizator avatar Master011 Martac Dragos Master011 IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 1,00 kb
Rundă Tema 12 clasele 9-10 2014/15 Status evaluat
Dată 21 ian. 2015 00:39:43 Scor 0
#include<cstdio>
using namespace std;

FILE *in = fopen("sgv.in","r");
FILE *out = fopen("sgv.out","w");

int parte_sup(int a, int b){
    if(a%b==0)
        return a/b;
    return a/b+1;
}

int main (){
    int C,T,M,X; fscanf(in,"%d%d%d%d",&C,&T,&M,&X);
    int y = 1, solt = 0, sold = 0;
    bool ok = 1;

    while(ok){
        if(C>sold){
            solt+=parte_sup(C-sold,y*M);
            sold+=parte_sup(C-sold,y*M)*M*y;
        }

        //fprintf(out,"%d SGV-uri au dupa %d zile %d material\n",y,solt,sold);
        if(parte_sup(X-sold,y*M)>T+parte_sup(X-sold+C-y*M*T,(y+1)*M)){
            sold-=C;sold+=T*y*M;
            solt+=T;
            //fprintf(out,"%d SGV-uri au dupa %d zile %d material si intra in functiune al %d-lea SGV\n",y,solt,sold,y+1);
            y++;
        }else{
            ok=0;
        }
    }
    solt+=parte_sup(X-sold,y*M);
    //fprintf(out,"%d SGV-uri au dupa %d zile %d material\n",y,solt,sold);
    fprintf(out,"%d\n",solt);
    return 0;
}