Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D
题链
Description
解一个线性规划(大雾)
Sol
单纯形我们发现我们可以暴力枚举转的圈数,而这个东西可以数论分块优化。
Code
#include <bits/stdc++.h> #define LL long long using namespace std; LL n,x,k,lb,ub,l,r,ans=-1; int main() { scanf("%lld%lld%lld%lld",&n,&l,&r,&k); x=(r>=l?r-l+1:r+n-l+1)%n; for(LL i=k,j,r;i;i=j){ j=k/(k/i+1);r=k/i; ub=min(2*n,i); lb=max(n,j+1); ub=min(ub,min((2*n+k-2*x+1)/(r+1),(k-x)/r)); lb=max(lb,(k-2*x+r-1)/r); if(ub>=lb)ans=max(ans,ub); } if(x<=k&&k<=x*2)ans=max(ans,n+min(k-x,x-1)+n-x+1); if(!x&&k==n)ans=max(ans,n+1); printf("%lld\n",~ans?ans-n:ans); }