思路:读懂题意还是很好写的,就是判断跳到哪里是空的,枚举就行,如果一直枚举k*d一定是会t的,中间需要优化一下,到达一个平台后,可以优化一下,计算到,直接跳到从k1开始枚举就行。
AC代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
int a[N],f[40][50];
int n,m,ans=-5;
void solve(){
int n,d,m,l;
cin>>n>>d>>m>>l;
int i=0;
for( i=0;i<n*m;i+=d){
if(i%m>l) break;
i+=(l-i%m)/d*d;
}
cout<<i<<"\n";
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
// cin>>t;
while(t--){
ans=-1;
solve();
}
}