Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- int k;
- int dp[100005];
- int main()
- {
- cin>>n>>k;
- int g;
- cin>>g;
- string z;
- string z2;
- ////broj na kompanii
- string c[g];
- int x[g];
- ////prva
- int y[g];
- ////vtora
- int result=2e9;
- for(int i=0; i<g; i++){
- cin>>c[i]>>x[i]>>y[i];
- dp[i]=2e9;
- }
- for(int i=0; i<g; i++){
- for(int j=0; j<=100000; j++){
- dp[j]=2e9;
- }
- dp[n]=0;
- for(int z=n; z>=k; z--){
- dp[z-1]=min(dp[z-1], dp[z]+x[i]);
- dp[z/2]=min(dp[z/2], dp[z]+y[i]);
- if(result>dp[k]){
- result=dp[k];
- z2=c[i];
- }
- }
- }
- cout<<z2<<" "<<result<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement