Guest User

Untitled

a guest
Feb 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5. int mat[403][403][403];
  6. //mat[current_location][final_location][refuel_count_left]
  7. vector<int> city;
  8. int fun(int s,int f, int r){
  9. if(s==f){
  10. return mat[s][f][r] = 0;
  11. }
  12. if(mat[s][f][r]!=0){
  13. return mat[s][f][r];
  14. }
  15. if(s+1==f || r==0){
  16. return mat[s][f][r] = city[f]-city[s];
  17. }
  18.  
  19. int opt = city[s] + (city[f]-city[s])/(r+1);
  20.  
  21.  
  22. int pos = lower_bound(city.begin()+s,city.begin()+f+1,opt) - city.begin();
  23.  
  24. mat[s][f][r] = max(fun(pos,f,r-1), city[pos] - city[s]);
  25.  
  26. //cout<<"s=" <<s<<" f="<<f<<" r="<<r<<" mat"<<mat[s][f][r]<<endl;
  27.  
  28. return mat[s][f][r];
  29. }
  30. int main(){
  31.  
  32. long long ans=0;
  33. int no_cities,no_vehicle;
  34. cin>>no_cities>>no_vehicle;
  35.  
  36. city.push_back(0);
  37. for(int i=1;i<=no_cities;++i){
  38. int b;cin>>b;
  39. city.push_back(b);
  40. }
  41. for(int i=0;i<no_vehicle;++i){
  42. int start,finish,costperkm,refuel_count;
  43. cin>>start>>finish>>costperkm>>refuel_count;
  44. long long vol_curr_vehicle = (long long)fun(start,finish,refuel_count)* (long long)costperkm;
  45. //cout<<jj<<" ";
  46. ans = max(ans,vol_curr_vehicle);
  47. }
  48. printf("%lld",ans);
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment