Submission #1115546

#TimeUsernameProblemLanguageResultExecution timeMemory
1115546EfeBabagilJobs (BOI24_jobs)C++14
0 / 100
159 ms10436 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N=1e5+5; const int mod=1e9+7; int32_t main() { int n,s; cin>>n>>s; vector<array<int,3>> jobs(n+1); vector<int> vis(n+1); int mon=s; jobs[0]={0,-1,0}; vis[0]=1; for(int i=1;i<=n;i++) { int a,b; cin>>a>>b; jobs[i]={a,b,i}; if(b==0) { if(a>0) { mon+=a; vis[i]=1; } } } vector<pair<int,int>> opt; for(int i=n;i>0;i--) { array<int,3> x=jobs[i]; if(x[0]<=0) continue; int prof=0; vector<int> done; int mn=0; //6 5 4 3 while(!vis[x[2]]) { done.push_back(x[2]); prof+=x[0]; if(prof<=0){ break; } if(mn+x[0]<0) mn+=x[0]; else mn=0; x=jobs[x[1]]; } if(prof>0) { for(int i=0;i<done.size();i++) vis[done[i]]=1; opt.push_back({-mn,prof}); } } sort(opt.begin(),opt.end()); for(int i=0;i<opt.size();i++) { //cout<<opt[i].first<<" "<<opt[i].second<<endl; if(opt[i].first<=mon<<opt[i].second>0) { mon+=opt[i].second; } } cout<<mon-s; return 0; } // 1-> 3 0 // 2-> -3 1 // 3-> -3 0 // 4-> 2 1 // 5-> 6 3 // 6-> -4 5

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:62:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for(int i=0;i<done.size();i++)
      |                         ~^~~~~~~~~~~~
Main.cpp:70:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=0;i<opt.size();i++)
      |                 ~^~~~~~~~~~~
Main.cpp:73:24: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   73 |         if(opt[i].first<=mon<<opt[i].second>0)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...