[Water] noip simulation competition exercise plan

Source: Internet
Author: User

1. exercise plan (exercise. Pas)

Question

The body is the capital of the revolution, and oiers should not neglect the health problem because of intense learning and waiting in front of the computer all day. Mr. X has designed his own exercise plan, but he does not know whether the plan is feasible. In other words, improper planning may overhead his physical strength, so Mr. X asks you to help him.

There are 1440 minutes a day, so small x lists the plans for the entire day from 1st to 1,440th minutes. The physical strength of a small X is represented by an integer. He exercises according to the schedule, and the physical strength of a small X is automatically increased by 1 per minute. If the physical strength of a small X at the end of a minute is less than or equal to zero, then the poor small X will be exhausted ......

Input (exercise. In)

The first line is two integers n and m separated by spaces, indicating the initial physical strength of small X and the number of projects planned respectively.

In the M line starting from the second row, each row describes an exercise item: name, start time A, end time B, and physical strength consumed per minute (separated by spaces ), indicates that the project starts at the beginning of minute a and ends at the end of minute B. Exercise items are displayed in ascending order of start time, so there is no time conflict between the two items.

Output (exercise. out)

The output includes two rows. If the plan is feasible, the first row outputs "accepted", and the second row outputs the remaining physical strength after the day; otherwise, the first row outputs "runtime error ", the output in the second row is exhausted in the last few minutes.

Example

Input

Output

10 1

Basketball 1 10 1

Accepted

1440

1 1

Nunchakus 1 1 2

Runtime error

1

Conventions

0 <n <= 2 ^ 31-1

0 <= m <= 500

The absolute values of all median values cannot exceed 2 ^ 31-1.

The name of each exercise item cannot exceed 20 characters, excluding spaces.

Ideas

simulate by minute .. There are still such domineering names: Dynamic Arrays built by prefixes and ideas...

Code
# include # include # include # include using namespace STD; struct node {int left, right, value ;}; node point [1000000]; int father [1000000]; int g; void buildtree (int I, int left, int right) // build {FATHER [I] = (INT) floor (I)/2.0; point [I]. left = left; point [I]. right = right; point [I]. value = 0; If (Left = right) {FATHER [I] = I;} else {buildtree (I <1, left, (INT) floor (right + Left)/2.0); buildtree (I <1) + 1, (INT) floor (right + Left)/2.0) + 1, right) ;}}// synchronized void Update (int x, int add, int left, int right, int now) // Change {int mid = (left + right)> 1; point [now]. value + = add; If (right-left) <1) {G = left; return;} If (left <= x) & (x <= mid )) {Update (x, add, left, mid, 2 * Now);} If (Mid + 1) <= x) & (x <= right )) {Update (x, add, Mid + 1, right, 2 * Now + 1) ;}}// specify int search (int x, int left, int right, int begin, int end) // query {If (Left = begin) & (Right = END) {return point [X]. value;} int mid = (begin + end)> 1; int ans = 0; If (left> = begin) & (right <= mid )) {ans + = search (2 * X, left, right, begin, mid);} // else if (left> = Mid + 1) on the left) & (right <= END) {ans + = search (2 * x + 1, left, right, Mid + 1, end );} // else {ans + = search (2 * X, left, mid, begin, mid) on the Right; ans + = search (2 * x + 1, Mid + 1, right, mid + 1, end) ;}// return ans;} // returns int main () {int n, m, K; CIN> N; buildtree, n); For (INT I = 1; I <= N; I ++) {int ad; CIN> ad; Update (I, AD, 1, n, 1);} CIN> m; For (INT I = 1; I <= m; I ++) {int TMP; CIN> TMP; if (TMP = 1) {int X, AD; CIN> x> ad; Update (x, AD, 1, n, 1 );} if (TMP = 2) {int p, q; CIN> P> q; cout
Result

[Water] noip simulation competition exercise plan

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.