Advertisement
Josif_tepe

Untitled

Nov 24th, 2021
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int n;
  5. int k;
  6. int dp[100005];
  7.  
  8. int main()
  9. {
  10.  
  11.  
  12. cin>>n>>k;
  13. int g;
  14. cin>>g;
  15. string z;
  16. string z2;
  17. ////broj na kompanii
  18. string c[g];
  19. int x[g];
  20. ////prva
  21. int y[g];
  22. ////vtora
  23. int result=2e9;
  24. for(int i=0; i<g; i++){
  25.     cin>>c[i]>>x[i]>>y[i];
  26.     dp[i]=2e9;
  27. }
  28.  
  29.  
  30. for(int i=0; i<g; i++){
  31.  
  32.     for(int j=0; j<=100000; j++){
  33.         dp[j]=2e9;
  34.     }
  35.     dp[n]=0;
  36.     for(int z=n; z>=k; z--){
  37.  
  38.             dp[z-1]=min(dp[z-1], dp[z]+x[i]);
  39.  
  40.             dp[z/2]=min(dp[z/2], dp[z]+y[i]);
  41.  
  42.         if(result>dp[k]){
  43.     result=dp[k];
  44.     z2=c[i];
  45.  
  46.     }
  47. }
  48. }
  49.  
  50. cout<<z2<<" "<<result<<endl;
  51.  
  52.  
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement