codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)
阿新 • • 發佈:2018-09-15
codeforce lin ostream pre pac cst names 選擇 iostream
題意:一個等差數列,首項為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> usingnamespace std; const int SZ=1000010,INF=0x7FFFFFFF; typedef long long lon; int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon a,b,n; cin>>a>>b>>n; for(lon i=0;i<n;++i) { lon ll,t,m; cin>>ll>>t>>m; lon lo=ll,hi=1e6+10; for(;lo<hi;) { lon mid=(lo+hi)/2; lon cur=0; lon a1=a+(ll-1)*b; lon len=(mid-ll+1); cur=a1*len+len*(len-1)*b/2; bool ok=0; if(len<=m) { ok=(a+(mid-1)*b)<=t; } else { ok=cur<=m*t&&(a+(mid-1)*b)<=t; } //cout<<"cur: "<<cur<<endl; //cout<<(m*t)<<" "<<ok<<" "<<lo<<" "<<hi<<" "<<"mid: "<<mid<<" "<<cur<<endl; if(!ok)hi=mid; else lo=mid+1; } cout<<(lo-1<ll?-1:lo-1)<<endl; } return 0; }
codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)