Submission #388724

#TimeUsernameProblemLanguageResultExecution timeMemory
388724IwanttobreakfreeFountain (eJOI20_fountain)C++98
0 / 100
1587 ms4520 KiB
#include <iostream> #include <vector> #include <set> using namespace std; int main(){ cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n,q,li,num; cin>>n>>q; int men=1e9,last=1e6; vector<pair<int,int> >fuen(n); vector<vector<int> >cone(n,vector<int>()); set<int> s; set<int>borrar; for(int i=0;i<n;i++){ cin>>fuen[i].second>>fuen[i].first; if(fuen[i].second<=men){ men=fuen[i].second; s.insert(i); } else if(fuen[i].second<last){ s.erase(i-1); s.insert(i); cone[i-1].push_back(i); } else{ s.insert(i); for(auto it=s.begin();it!=s.end();it++){ if(fuen[*it].second<fuen[i].second){ cone[*it].push_back(i); borrar.insert(*it); } } for(int x:borrar)s.erase(x); } last=fuen[i].second; } bool sol=true; while(q--){ cin>>num>>li; num--; sol=true; while(true){ li-=fuen[num].first; if(li<1)break; if(cone[num].empty()){ sol=false; break; } else{ for(int x:cone[num]){ num=x; } } } if(!sol)cout<<0<<'\n'; else cout<<num+1<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...