#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
#define P pair<ll,ll>
#define PP map<ll,priority_queue<P,vector<P>,greater<P> > >
int A[N][2];
PP ma;
vector<P> jl[N];
map<ll,ll> qa;
int num[N];
queue<int> qqa;
void insert(int x,int y)
{
ll &u = qa[x];
u+=y;
priority_queue<P,vector<P>,greater<P> > &temp = ma[x];
while(!temp.empty())
{
P x = temp.top();
if(x.first<=u)
{
temp.pop();
num[x.second]--;
if(num[x.second]==0) qqa.push(x.second);
}else{
break;
}
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int g;
cin>>g;
for(int i=1;i<=g;i++)
{
cin>>A[i][0]>>A[i][1];
}
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>num[i];
for(int j=1;j<=num[i];j++)
{
ll a,b;
cin>>a>>b;
ma[a].push({b,i});
}
int k;
cin>>k;
for(int j=1;j<=k;j++)
{
ll a,b;
cin>>a>>b;
jl[i].push_back({a,b});
}
}
for(int i=1;i<=n;i++)
{
if(num[i]==0)
qqa.push(i);
}
for(int i=1;i<=g;i++) insert(A[i][0],A[i][1]);
int cnt=0;
while(!qqa.empty())
{
int x = qqa.front();
qqa.pop();
cnt++;
for(auto j:jl[x])
{
insert(j.first,j.second);
}
}
cout<<cnt<<endl;
return 0;
}
https://codeforces.com/gym/104417/problem/B
最新推荐文章于 2024-07-19 17:07:49 发布