"CF" 3B lorry

Source: Internet
Author: User

There are several problems on the Internet in this topic. In fact, simple greedy + sort, no need to do so complex.
Once tot+curv > V, obviously curv==2, there are three possibilities:
(1) Remove the smallest curv==1 pp, loading the current p;
(2) Remove the following Max Curv==1 P, and load;
(3) is currently optimal (i.e., the type of curv==1 is not present), while the previous PP is better than the current p. (This situation does not require a special sentence)

1 /*3B*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at  - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A  thetypedefstructnode_t { +     intT, p, id; -FriendBOOL operator< (Constnode_t& A,Constnode_t&b) { $         if(A.P = =b.p) $             returnA.T <b.t; -         returnA.P >B.P; -     } the } node_t; - Wuyi Const intMAXN = 1e5+5; the node_t ND[MAXN]; -  Wu intMain () { -Ios::sync_with_stdio (false); About #ifndef Online_judge $Freopen ("data.in","R", stdin); -Freopen ("Data.out","W", stdout); -     #endif -      A     intN, v; +      thescanf"%d%d", &n, &v); -Rep (I,1, n+1) { $scanf"%d%d", &AMP;ND[I].T, &ND[I].P); theNd[i].id =i; the         if(nd[i].t = =1) theND[I].P + =ND[I].P; the     } -      inSort (nd+1, nd+1+n); the      the     intI, J, K, p, pp =0, pid, tot =0; About     intAns =0, TMP; the vi VC; the      thei =1; +      while(I <=N) { -         if(nd[i].t = =1) { theK =1;Bayip = nd[i].p>>1; thePP =p; thePID =nd[i].id; -}Else { -K =2; thep =ND[I].P; the         } the          the         if(Tot+k <=v) { -Tot + =K; theAns + =p; the VC.PB (nd[i].id); the}Else if(PP) {94             //tot+k > V the             //must be k = = 2 the             //And Pre has a 1 thej = i+1;98              while(J<=n && nd[j].t!=1) About++J; -             101             //no type 1 but could be pp < P (becase p is half if the ND[PID].P).102             if(J >N) {103TMP =0;104}Else { theTMP = nd[j].t>>1;106             }107             //Solve108             if(P-pp >tmp) {109                 //Erase PID and add new ID the                  for(Vi::iterator iter=vc.begin (); Iter!=vc.end (); + +ITER) {111                     if(*iter = =pid) { the Vc.erase (ITER);113                          Break; the                     } the                 } the VC.PB (nd[i].id);117Ans + = Ppp;118}Else if(TMP) {119                 //add nd[j].id; - VC.PB (nd[j].id);121Ans + =tmp;122             }123             124              Break; the         }126         127         if(Tot = =v) -              Break;129++i; the     }131      theprintf"%d\n", ans);133Rep (I,0, SZ (VC)) {134printf"%d", Vc[i]);135     }136Putchar ('\ n');137     138 #ifndef Online_judge139printf"Time =%d.\n", (int) clock ()); $     #endif141     142     return 0;143}

"CF" 3B lorry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.