1073 Thunder Fighter

Source: Internet
Author: User

problem Description

Wind wind has recently been fascinated by a flying game-"Thunder Fighter", warplanes are divided into Bai, green Samsung, blue four stars, purple five-star, four kinds of quality. Of course, the most powerful is the purple five-star fighter.

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".

Code
#include <cstdio>#include <algorithm>using namespace STD;intMain () {intN, a[1005], s[5]; while(scanf("%d", &n)! = EOF) { for(inti =0; I <4; i++)scanf("%d", &s[i]);intAns =0; for(inti =0; i < N; i++) {scanf("%d", &a[i]);        Ans + = a[i]; } sort (A, a + N); for(inti =0; I <4; ) {intflag = S[i]; for(intj =0; J < N; J + +)if(A[j] >= s[i])                    {ans-= a[j]; A[J] = s[i] =0; Break; } for(intj = N-1; J >=0&& S[i]; j--)if(A[j])                    {ans-= a[j];                    S[i]-= a[j]; A[J] =0; Break; }if(flag = = S[i]) Break;if(S[i] <=0) i++; }if(s[3] <=0)printf("YES%d\n", ans);Else             printf("no\n"); }return 0;}

1073 Thunder Fighter

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.