1 solutions
-
0
思路:
每个结点Xa表示0到a有多少个数在集合Z内
区间用临时前缀和的方式表示
则不等式为:Xb-(Xa-1)≥C
代码:
#include<bits/stdc++.h> using namespace std; const int N=50010; const int INF=0x3f3f3f3f; struct Edge{int to,w;}; vector<Edge>g[N]; int dist[N],cnt[N]; bool inq[N]; bool spfa(int s,int t){ memset(dist,-0x3f,sizeof(dist)); memset(cnt,0,sizeof(cnt)); memset(inq,0,sizeof(inq)); queue<int>q;q.push(s); dist[s]=0,inq[s]=true; while(!q.empty()){ int u=q.front();q.pop(); inq[u]=false; for(auto &e:g[u]){ int v=e.to,w=e.w; if(dist[v]<dist[u]+w){ dist[v]=dist[u]+w; if(!inq[v]){ q.push(v); inq[v]=true; if(++cnt[v]>t-s+1) return false; } } } } return true; }int main(){ int n; cin>>n; int min_a=INF,max_b=-INF; for(int i=0;i<n;i++){ int a,b,c; cin>>a>>b>>c; a++,b++; g[a-1].push_back({b,c}); min_a=min(min_a,a-1); max_b=max(max_b,b); } for(int i=min_a;i<max_b;i++) g[i].push_back({i+1,0}), g[i+1].push_back({i,-1}); spfa(min_a,max_b); cout<<dist[max_b]<<endl; return 0; }
- 1
Information
- ID
- 89
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 8
- Tags
- # Submissions
- 42
- Accepted
- 6
- Uploaded By