Submission #388722

#TimeUsernameProblemLanguageResultExecution timeMemory
388722IwanttobreakfreeFountain (eJOI20_fountain)C++17
30 / 100
1573 ms5168 KiB
#include <iostream> #include <vector> #include <set> using namespace std; int main(){ int n,q,li,num; cin>>n>>q; int men=1e9; 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{ s.insert(i); for(auto it=s.begin();it!=s.end();it++){ //cout<<*it<<' '; if(fuen[*it].second<fuen[i].second){ cone[*it].push_back(i); //cout<<*it<<' '<<i<<' '; borrar.insert(*it); } } for(int x:borrar)s.erase(x); //cout<<'\n'; } } bool sol=true; while(q--){ cin>>num>>li; num--; sol=true; while(true){ //cout<<num<<' '<<li<<' '; 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...