The proceeds from each income are independent.
Calculate a bit of yield, accumulate.
#define_crt_secure_no_warnings#include<iostream>#include<algorithm>#include<vector>using namespacestd;structdd{intd, E;} ndd[2505];structddd{intS, F, r;} mddd[2505];BOOLDddcomp (ddd A, ddd b) {returnA.S <B.S;}intrate[100005];intMaxintAintb) { returnA>b?a:b;}intMain () {intt, N, M; scanf ("%d", &t); for(intW =1; W <= t; ++W) {memset (rate,0,sizeof(rate)); scanf ("%d%d", &n, &m); for(inti =0; I < n; ++i) scanf ("%d%d", &NDD[I].D, &NDD[I].E); for(inti =0; I < m; ++i) scanf (" %d%d%d", &mddd[i].s, &MDDD[I].F, &MDDD[I].R); Sort (mddd, mddd+ M, dddcomp);//reading and sorting Data//Rate[],rate[i]=max (Rate[i+1],rate[j]+r[i-j]), just consider the situation of r[i-j] intpos = M-1; for(inti = mddd[m-1].S; I >= mddd[0].S; --i) { intMX = rate[i +1]; while(Pos >=0&& i = =mddd[pos].s) {MX= Max (MX, MDDD[POS].R +RATE[MDDD[POS].F]); --POS; } Rate[i]=MX; } for(inti = mddd[0].S-1; I >=0; --i) rate[i]= Rate[i +1]; //calculate the income of revenue separately Long Longsum =0; for(inti =0; I < n; ++i) {Sum+ = RATE[NDD[I].D] *NDD[I].E; } printf ("Case #%d:\n%.2lf\n", W, (Double) Sum/100.0); }}
Best Financing (HD4833)