HDU 2111 saving HDU

Source: Internet
Author: User

This topic allows me to understand the specific function overload of the priority queue. <it is used to indicate the priority

# Include <stdio. h> # include <math. h> # include <queue> # include <algorithm> # include <iostream> # include <string. h> using namespace STD; struct node {int Pi, mi; bool operator <(const node A) const {return pI <. pi; // indicates that the highest priority is top }}; int main () {int V; while (~ Scanf ("% d", & V) {priority_queue <node, vector <node>, less <node> q; int N; scanf ("% d", & N); While (n --) {int Pi, mi; node no; scanf ("% d", & Pi, & mi); No. pi = PI; No. mi = mi; q. push (NO);} int ans = 0; while (! Q. empty () & V) {If (Q. top (). mi <= V) {ans + = Q. top (). mi * q. top (). pi; V-= Q. top (). mi; node no; NO = Q. top (); q. pop ();} else {ans + = V * q. top (). pi; V = 0 ;}} printf ("% d \ n", ANS) ;}return 0 ;}

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.