Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define MAX(a,b) ((a>b)?a:b)
- #define MIN(a,b) ((a<b)?a:b)
- #define loop(i, a, b) for(int i=(a);i<=(b);i++)
- #define pf(x) printf(x);
- #define dbg(x) printf("\n--bug: %d --\n",x)
- #define PI 2*acos(0.0)
- #define all(x) x.begin(),x.end()
- #define ll long long
- #define pb push_back
- #define NL printf("\n")
- using namespace std;
- struct items{
- int time,des,val,idx;
- }a[105];
- int n;
- int dp[105][2005];
- int dir[105][2005];
- vector<items> res;
- bool cmp(items a,items b)
- {
- return a.des<b.des;
- }
- bool cmp_idx(items a,items b)
- {
- return a.idx<b.idx;
- }
- int fun(int item,int clk)
- {
- //cout<<"working on: "<<item<<" "<<clk<<endl;
- if(item>=n) return 0;
- if(dp[item][clk]!=-1) return dp[item][clk];
- int profit1=0;
- int profit2=0;
- if((clk+a[item].time) < a[item].des)
- {
- profit1= a[item].val + fun(item+1,clk+a[item].time);
- }
- else profit1=0;
- profit2=fun(item+1,clk);
- dir[item][clk]=(profit1>profit2)?1:2;
- return dp[item][clk]=max(profit1,profit2);
- }
- void solution_print(int item,int clk)
- {
- if(dir[item][clk]==1)
- {
- res.pb(a[item]);
- solution_print(item+1,clk+a[item].time);
- }
- else if(dir[item][clk]==2)
- {
- solution_print(item+1,clk);
- }
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- for(int i=0;i<105;i++)
- {
- for(int j=0;j<2005;j++)
- {
- dp[i][j]=-1;
- dir[i][j]=-1;
- }
- }
- cin>>n;
- loop(i,0,n-1)
- {
- scanf("%d%d%d",&a[i].time,&a[i].des,&a[i].val);
- a[i].idx=i+1;
- }
- sort(a,a+n,cmp);
- // loop(i,0,n-1) cout<<a[i].time<<" "<<a[i].des<<" "<<a[i].val<<endl;
- // NL;
- cout<<fun(0,0)<<endl;
- solution_print(0,0);
- // sort(all(res),cmp_idx);
- cout<<res.size()<<endl;
- if(res.size()<=0) return 0; ///problem is here
- loop(i,0,res.size()-1)
- {
- printf("%d ",res[i].idx);
- }
- NL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement