//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<map>
#include<set>
using namespace std;
#define MP(x,y) make_pair((x),(y))
#define PB(x) push_back(x)
typedef __int64 LL;
//typedef unsigned __int64 ULL;
/* ****************** */
const LL INF = 1LL<<55;
const double INFF = 1e100;
const double eps = 1e-8;
const LL mod = 10000000007LL;
const int NN = 100010;
const int MM = 400010;
/* ****************** */
bool ok(LL M, LL S, LL T)
{
S -= 120*(T/7);
T %= 7;
if (S <= 0) return true;
//枚举积累魔法的时间,这里有个显然的东西,如果积累魔法,一定会去使用
for (LL i = 0; i <= T; i ++)
{
LL temp = min((M + i*4)/10, T-i);
if (S - temp*60 - 17*(T-i-temp) <= 0)
return true;
}
return false;
}
int main()
{
LL M, S, T, l, r, mid;
cin>>M>>S>>T;
if (ok(M, S, 0))
{
puts("Yes 0");
}
else if(!ok(M, S, T))
{
puts("No");
}
else
{
l = 0, r = T;
while (l + 1 < r)
{
mid = (l + r)>>1;
if (ok(M, S, mid))
r = mid;
else
l = mid;
}
cout<<"Yes "<<r<<endl;
}
return 0;
}原文:http://blog.csdn.net/wxq_wuxingquan/article/details/38761457