Pentru această operație este nevoie să te autentifici.
Cod sursă (job #819619)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | SCV (clasele 9-10) | Compilator | cpp-32 | 1,08 kb |
Rundă | antrenament1 | Status | evaluat |
Dată | 9 apr. 2025 10:28:36 | Scor | 30 |
#include <fstream>
using namespace std;
ifstream fcin("scv.in");
ofstream fout("scv.out");
int c,m,t,x;
inline int f(int val)
{
int r=m,s=0, ok=0, poz=-1;
for(int i=0; i<val; i++)
{
if(poz==i)
{
r+=m;
ok=0;
}
s+=r;
if(s>=x) return 1;
if(s>=c && ok==0)
{
int nrz=t;
int sum=(s-c+r*(t-1));
if( ((x-s)/r+1) > (x-sum)/(r+m)+1+nrz)
{
s-=c;
poz=i+t+1;
ok=1;
}
else
{
if(((x-s)/r+1)+i-1<val)
return 1;
else
return 0;
}
}
}
return 0;
}
int main()
{
fcin>>c>>t>>m>>x;
int st=1, dr=1e9, sol=-1;
while(st<=dr)
{
int mij=(st+dr)/2;
if(f(mij))
{
dr=mij-1;
sol=mij;
}
else
{
st=mij+1;
}
}
fout<<sol;
return 0;
}