2012 Borrowing The Classroom

Source: Internet
Author: User

Borrow the ClassroomTitle 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 is described by three positive integers, respectively, DJ,SJ,TJ, indicating that a renter needs to rent from SJ to TJ Days

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.

input/output format

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

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 are m lines, each line containing three positive integers dj,sj,tj, indicating the number of leases, the start of lease, the end of

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 Format

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
4 3 2 5 4 3 2 1 3 3 2 4 4 2 4

Sample Output
-1 2

Input/Output Sample description

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 the data, there are 10;

For 30% of the data, there are 1000;

For 70% of the data, there are 1≤n,m≤10^5;

For 100% of the data, there is 1≤n,m≤10^6,0≤ri,dj≤10^9,1≤sj≤tj≤n.

//the use of prefixes and;//0,0,0,0,0,0;//2 3 5 Add 2 between [3,5];//0,2,0,0,0,-2;//accumulate 0,2,2,2,2,0 in succession;#include <cstdio>intn,m,r[1000002],sum[1000002],g,sumn,ans=-1;structnode{intd,s,t;} sz[1000002];intFindintx) {    inttmp=0; if(x>sumn) {         for(inti=sumn+1; i<=x;i++) {SUM[SZ[I].S]+=SZ[I].D; SUM[SZ[I].T+1]-=SZ[I].D; } sumn=x; }    Else{         for(inti=sumn;i>x;i--) {//to find the earliest non-conforming order,SUM[SZ[I].S]-=SZ[I].D;//Therefore, the impact of the subsequent elimination;sum[sz[i].t+1]+=SZ[I].D; } sumn=x; }     for(intI=1; i<=n+1; i++) {tmp+=Sum[i]; if(Tmp>r[i])return 0; }    return 1;}voidDivintXintY) {//two points;     while(x<y) {g= (x+y)/2; if(Find (g) = =0) {y=G; }        Elsex=g+1; }    if(Find (x) = =0) ans=x; Elseans=y;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) scanf ("%d", r+i);  for(intI=1; i<=m;i++) scanf ("%d%d%d",&sz[i].d,&sz[i].s,&sz[i].t); Div (1, M); if(Ans==m&&find (ans) = =1) {printf ("%d",0); }    Else{printf ("-1\n%d\n", ans); }    return 0;}
View Code

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