Acdream 1073 (greedy)

Source: Internet
Author: User

Test instructions
The fighter is divided into two types: upgrade and advanced.
Upgrade: Raise the level of the fighter, but the aircraft quality is unchanged.
Advanced: The fighter can be upgraded to a star (Bai-Green Samsung--blue four-star).

In order to simplify the problem, the following rules are stipulated in the aircraft:
White two-star:
Start level LV1 level, full level Lv25 level.
LV1 upgrade to LV25, a total of a experience is required.
Advanced to green Samsung conditions: After the full level of LV25, can be advanced.
Green Samsung:
Start level LV25 level, full level LV30 level.
LV25 upgrade to LV30, a total of B experience is required.
Advanced to blue four-star condition: After the full-level Lv30, the order can be advanced.
Blue Four-star:
Start level LV30 level, full level Lv60 level.
LV30 upgrade to Lv60, a total of C experience is required.
Advanced to purple five-star condition: After the full-level Lv60, the square can be advanced.
Purple five-Star:
Start level Lv60 level, full level Lv75 level.
Lv60 upgrade to Lv75, a total of D experience is required.
Full-scale LV75, the strongest fighter was born!

Now there are 1 Lv1-level Bai in the wind hand, and n experience Ball (can upgrade the ball ball ~ ~ ~), each experience ball has a certain amount of experience.
Each wind can only use one experience ball to upgrade the fighter, and each experience ball can only be used once and then disappear.
In addition, wind wind has a habit. Is that each time the first choice will be able to upgrade the fighter to the corresponding star of the full level of the smallest experience ball. If the remaining experience ball of the largest experience ball can not be the current aircraft to the full level, then the wind will choose the remaining experience of the most experienced ball inside the experience of the ball to upgrade the aircraft.
If according to wind wind way to upgrade the aircraft, wind wind can successfully upgrade their fighter to full-scale LV75 purple fighter?
If so, please tell the wind, what is the sum of the experience of the last unused experience ball he has left?

Note: If you use an experience ball to upgrade the fighter to full scale, then the extra experience will not accumulate, then you need to advance to the next level of aircraft quality, improve the level of full-scale. Before you can continue with the upgrade.
For example:
Now there is a green Samsung LV29 fighter, and it takes 80 of experience to upgrade to full-scale Lv30. If you have used experience for 9999 of experience ball. You can only upgrade a fighter to a full-scale Lv30, not upgrade to the LV31 level, and XP will not accumulate. Because the experience ball is used, it cannot be advanced. Since the advanced level needs to be full-scale, it can only be advanced.
In addition, it is worth mentioning that: if it is a green Samsung LV9 aircraft, also need 10 of experience to upgrade to LV10, and Lv10 to Lv11 need 15 points of experience, Lv11 to LV12 need 22 points of experience. Then you will be able to upgrade the fighter directly to the LV11 with an experience value of 30, and it will require 17 points of experience to upgrade to LV12. (That is, you have not reached a full-scale fighter, the use of experience orbs can be upgraded across levels, and after the full level, you need to step to the next quality before you can continue to upgrade).
Input

Input contains multiple sets of data for each set of data:
First line: N (indicates there are N experience orbs, 1<=n<=1000)
The second line: A B C D (the total experience required for each star to ascend from the starting level to the corresponding star level, see the above topic for details, 1<=a,b,c,d<=99999)
Third line: N experience orbs Exp[i] (1<=exp[i]<=99999)
Output

If you can advance to the full level Lv75 purple fighter, Output "YES" and output the last remaining unused experience ball experience sum is how much.
If not, output "no".
Sample Input

3
400 250 800 2000
99999 99999 99999
4
400 2000 5000 10000
9999 9999 9999 9999
4
400 2000 5000 10000
99999 99999 99999 99999
5
1000 2000 8000 10000
1000 2000 5000) 10000 20000

Sample Output

NO
NO
YES 0
YES 5000
The main thing: simulation directly according to test instructions, note that if all the experience of the ball so that it can not be advanced, then choose the maximum experience of the ball Plus, and then choose from the beginning, whether there is to let him advance the experience of the ball.

#include <stdio.h>#include <string.h>#include <algorithm>using namespace STD;Const intN =1005;intN, a[4], B[n], vis[n];intMain () { while(scanf("%d", &n) = =1) { for(inti =0; I <4; i++)scanf("%d", &a[i]); for(inti =0; I < n; i++)scanf("%d", &b[i]);if(N <4) {printf("no\n");Continue; }memset(Vis,0,sizeof(VIS)); Sort (b, B + N);intI, j, cnt =0; for(i =0; I <4; i++) { for(j =0; J < N; J + +)if(!vis[j] && b[j] >= a[i]) {Vis[j] =1; cnt++; Break; }if(J! = N)Continue; for(j = n-1; J >=0; j--) {if(!vis[j]) {Vis[j] =1;                    A[i]-= b[j]; i--; Break; }            }        }if(CNT = =4) {printf("YES");intnum =0; for(inti =0; I < n; i++)if(!vis[i]) num + = B[i];printf("%d\n", num); }Else            printf("no\n"); }return 0;}

Acdream 1073 (greedy)

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.