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