Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int mat[403][403][403];
- //mat[current_location][final_location][refuel_count_left]
- vector<int> city;
- int fun(int s,int f, int r){
- if(s==f){
- return mat[s][f][r] = 0;
- }
- if(mat[s][f][r]!=0){
- return mat[s][f][r];
- }
- if(s+1==f || r==0){
- return mat[s][f][r] = city[f]-city[s];
- }
- int opt = city[s] + (city[f]-city[s])/(r+1);
- int pos = lower_bound(city.begin()+s,city.begin()+f+1,opt) - city.begin();
- mat[s][f][r] = max(fun(pos,f,r-1), city[pos] - city[s]);
- //cout<<"s=" <<s<<" f="<<f<<" r="<<r<<" mat"<<mat[s][f][r]<<endl;
- return mat[s][f][r];
- }
- int main(){
- long long ans=0;
- int no_cities,no_vehicle;
- cin>>no_cities>>no_vehicle;
- city.push_back(0);
- for(int i=1;i<=no_cities;++i){
- int b;cin>>b;
- city.push_back(b);
- }
- for(int i=0;i<no_vehicle;++i){
- int start,finish,costperkm,refuel_count;
- cin>>start>>finish>>costperkm>>refuel_count;
- long long vol_curr_vehicle = (long long)fun(start,finish,refuel_count)* (long long)costperkm;
- //cout<<jj<<" ";
- ans = max(ans,vol_curr_vehicle);
- }
- printf("%lld",ans);
- return 0;
- }
Add Comment
Please, Sign In to add comment