本来是DP的一个题目,不过也可以用动态维护的方法做。
一秒一次循环,每次循环s1,s2。s2表示只是用闪现能到达的距离,s1是这个时间能达到的最远距离,每次s1+17(走路),再用s2更新s1。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int m,s,t;
scanf("%d%d%d",&m,&s,&t);
int time=0,s1=0,s2=0;
while(t&&s1<s)
{
s1+=17;
if(m>=10)
{
s2+=60;
m-=10;
}
else
m+=4;
t--;
time++;
s1=max(s1,s2);
}
if(s1>=s)
{
cout << "Yes" << endl ;
cout << time << endl ;
}
else
{
cout << "No" << endl ;
cout << s1 << endl ;
}
return 0;
}