codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)

时间:2023-05-01 12:02:56

题意:一个等差数列,首项为a,公差为b,无限长。操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少。

这么一个简单题吞了我3小时的时间。主要是没考虑全。

首先,得出ll位置的值a1,如果a1>t那么不可行。

然后分2种情况。

1.区间长度<=m,那么只要右端<=t就行,否则不行。

2.区间长度>m,区间内元素总和<=m*t,且右端<=t就行,否则不行。这个我猜到了,不过忽略了右端<=t,因此wa了很久。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon a,b,n;
cin>>a>>b>>n;
for(lon i=;i<n;++i)
{
lon ll,t,m;
cin>>ll>>t>>m;
lon lo=ll,hi=1e6+;
for(;lo<hi;)
{
lon mid=(lo+hi)/;
lon cur=;
lon a1=a+(ll-)*b;
lon len=(mid-ll+);
cur=a1*len+len*(len-)*b/;
bool ok=;
if(len<=m)
{
ok=(a+(mid-)*b)<=t;
}
else
{
ok=cur<=m*t&&(a+(mid-)*b)<=t;
}
//cout<<"cur: "<<cur<<endl;
//cout<<(m*t)<<" "<<ok<<" "<<lo<<" "<<hi<<" "<<"mid: "<<mid<<" "<<cur<<endl;
if(!ok)hi=mid;
else lo=mid+;
}
cout<<(lo-<ll?-:lo-)<<endl;
}
return ;
}