HDU2111: Saving HDU

Source: Internet
Author: User

Problem Description said that the Haidong group is facing internal and diplomatic difficulties, and the company's elders only have the XHD couple. Obviously, as a businessman who has been fighting for many years, XHD won't sit down. One day, when he was thinking hard about how to solve the problem, he suddenly thought of his own biography. when the company was founded, his father sent a gift as a gift, and Xu told me at the time, don't open it unless you have. "Isn't it the most necessary time ?", While thinking, XHD found this well-managed tip and opened it. There was only one sentence in it: "Hangzhou North Lu qianrendong youbao ". Let alone, XHD picked up a big pocket and set off. He knew this qiandongdong. When he was a child, his father took him to this hidden intersection and told him that it was a qiandongdong. Now he understands the meaning of his father's sentence. Although I was a bit impressed, XHD took a lot of energy to find this unusually hidden hole and walked into it. It was almost stunned and really dazzled! However, although there are many types of baby, there are not many types of baby, of course, the price of each type of baby unit volume is also different, in order to save HDU, now, please help us calculate the maximum value that XHD can bring back as soon as possible? (Assuming that the baby can be split, the value after the split is proportional to the corresponding volume) Input contains multiple test instances, the first line of each instance is two integers v and n (v, n <100) indicates the size of the pocket and the type of the baby, and the next n rows contain two integers pi and mi (0 <pi, mi <10 ), represents the unit price and corresponding volume of a certain type of baby, respectively, and end the input when v is 0. Output for each test instance, please Output the maximum value that XHD can retrieve, each instance occupies a line of Output. Sample Input2 23 12 30 Sample Output5 can help HDU out of crisis? For details about the problem, refer to [cpp] # include <iostream> # include <stdlib. h> using namespace std; struct bb {int p [105]; int m [105];} bao; int main () {int v, n; while (cin> v, v) {cin> n; int I, j, t; for (I = 0; I <n; I ++) {cin> bao. p [I]> bao. m [I] ;}for (I = 0; I <n-1; I ++) {int k = I; for (j = I + 1; j <n; j ++) {if (bao. p [j]> bao. p [k]) k = j;} t = bao. p [I]; bao. p [I] = bao. p [k]; bao. p [k] = t; t = bao. m [I]; bao. m [I] = bao. m [k]; bao. m [k] = t;} int sum_v = 0, sum = 0; for (I = 0; I <n; I ++) {sum_v + = bao. m [I]; if (sum_v <= v) sum + = bao. p [I] * bao. m [I]; else {int t = sum_v-v; sum + = bao. p [I] * (bao. m [I]-t); break ;}} cout <sum <endl;} 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.