Codevs 1217 borrowing the classroom

Source: Internet
Author: User

Transmission Door

1217 borrowing the classroom

2012 Noip National League Improvement Group

time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle Description Description

It is often necessary to rent a classroom during college. Large to the Department to organize activities, small to study group discussion, all need

Apply to the school to borrow the classroom. The classroom size function is different, borrows the classroom person's identity to be different, borrows the classroom The procedure also is dissimilar.

In the face of the vast amount of information rented classrooms, we naturally want to program to solve this problem.

We need to deal with the next n days of borrowing classroom information, where I day school has RI classrooms available for rent. Total m part

Orders, each order with three positive integer description, respectively, DJ, SJ, TJ, indicating that a renter needs from SJ Day to the first TJ Day rent

To borrow the classroom (including SJ Day and TJ Day), we need to rent a DJ classroom every day.

We assume that the renter has no requirement for the size and location of the classroom. For each order, we only need to ask each

For DJ classrooms, and what classrooms they are in, and whether they are the same classroom each day is not considered.

The principle of borrowing a classroom is first come first served, that is, we have to order each order in order to assign the teaching

Room. If you encounter an order that is not fully satisfied during the allocation process, you will need to stop the classroom assignment and notify the current

Ask someone to modify the order. The inability to meet here means that the number of classrooms remaining at least one day from the day of SJ to TJ is less than a DJ.

Now we need to know if there will be an order that is not fully satisfied. If there is, need to inform which applicant to modify

Order.

Enter a description Input Description

The first line contains two positive integers n, m, representing the number of days and orders.

Improve group Day2

The second line contains n positive integers, where the number of I is RI, which indicates the number of classrooms that can be used for lease on day I.

Next there is M line, each line contains three positive integer DJ, SJ, TJ, indicating the number of leases, lease start, end respectively in

The first day.

Each row is separated by a space between the two numbers that are adjacent to each other. The number of days and orders is numbered with an integer starting from 1.

Output description Output Description

If all orders are satisfied, the output is only one row and contains an integer 0. Otherwise (orders cannot be fully satisfied)

Output two lines, the first line outputs a negative integer-1, and the second line outputs the applicant number to modify the order.

Sample input Sample Input

4 3

2 5 4 3

2 1 3

3 2 4

4 2 4

Sample output Sample Output

-1

2

Data range and Tips Data Size & Hint

"Input and Output sample description"

Classroom.out

-1

2

After the 1th order is fulfilled, the number of classrooms remaining for 4 days is 0,3,2,3. 2nd Order Request 2nd day to

3 classrooms are provided daily on the 4th day, while the remaining number of classrooms on the 3rd day is 2 and therefore cannot be fulfilled. Assignment Stop, notice

2 applicants modify the order.

"Data Range"

For 10% of data, there are 1 ≤  N, M ≤ 10;

For 30% of data, there are 1 ≤ N, M ≤ 1000;

For 70% of data, there are 1 ≤   N, M ≤ 105;

For 100% of data, there are 1 ≤ N, M ≤ 10^6, 0 ≤ RI, dj≤ 10^9, 1 ≤ sj≤ tj≤ N.

#include <cstdio>#include<iostream>#include<cstring>#defineN 1000100using namespacestd;intn,m,mid,ans=0;intRi[n],d[n],s[n],t[n],si[n];BOOLPdintk) {memset (SI,0,sizeof(SI)); intsum=0;  for(intI=1; i<=k;i++) {Si[s[i]]+=D[i]; Si[t[i]+1]-=D[i]; }     for(intI=1; i<=n;i++) {sum+=Si[i]; if(Sum>ri[i])return 0; }    return 1;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) scanf ("%d",&Ri[i]);  for(intI=1; i<=m;i++) scanf ("%d%d%d",&d[i],&s[i],&T[i]); intL=1, r=m;  while(l<=r) {Mid= (l+r)/2; BOOLf=PD (mid); if(!f) ans=mid,r=mid-1; ElseL=mid+1; }    if(ANS) printf ("-1\n%d\n", ans); Elsecout<<0<<Endl;}

Codevs 1217 borrowing the classroom

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.