标签:sample 问题 ble 最大 区间合并 title mem eof 测试数据
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 197 Accepted Submission(s): 78
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define met(a,b) memset(a,b,sizeof a) #define pb push_back #define mp make_pair #define rep(i,l,r) for(int i=(l);i<=(r);++i) #define inf 0x3f3f3f3f using namespace std; typedef long long ll; const int N = 1e5+50;; const int M = 17; const int mod = 1e9+7; const int mo=123; const double pi= acos(-1.0); typedef pair<int,int>pii; int n,m; ll sum[N],sum2[N]; vector<pii>vec; struct man{ int l,r; }a[N]; bool cmp(const man &s,const man &d){ if(s.l==d.l)return s.r<d.r; return s.l<d.l; } int main(){ while(~scanf("%d%d", &n, &m)) { for(int i=1;i<=n;i++){ scanf("%d%d",&a[i].l,&a[i].r); } sort(a+1,a+1+n,cmp); int now=1; vec.clear(); met(sum,0);met(sum2,0); for(int i=2;i<=n;i++){ if(a[i].l<=a[now].r)a[now].r=max(a[now].r,a[i].r); else { vec.pb(mp(a[now].l,a[now].r)); now=i; } } vec.pb(mp(a[now].l,a[now].r)); int sz=vec.size(); ll ans=0,ss,dd; sum[0]=0; sum2[0]=vec[0].second-vec[0].first+1; for(int i=1;i<sz;i++){ sum[i]=sum[i-1]+vec[i].first-vec[i-1].second-1; sum2[i]=sum2[i-1]+vec[i].second-vec[i].first+1; } for(int i=0;i<sz;i++){ int ll=0,rr=i,res=-1; while(ll<=rr){ int mid=(ll+rr)/2; ss=sum[i]-sum[mid]; if(ss<=m)rr=mid-1,res=mid; else ll=mid+1; } if(res==0)dd=sum2[i]; else dd=sum2[i]-sum2[res-1]; ss=sum[i]-sum[res]; ans=max(ans,dd+ss+(m-ss)); } printf("%lld\n",ans); } return 0; }
HDU 6119 2017百度之星初赛B 小小粉丝度度熊 (二分)
标签:sample 问题 ble 最大 区间合并 title mem eof 测试数据
原文地址:http://www.cnblogs.com/jianrenfang/p/7354450.html