NOIP2012 borrowed the Classroom

Source: Internet
Author: User

Their yy out of the method, time complexity for n*m, but in fact not so much, Codevs on the slowest group has more than 300 Ms.

For each order, add the required number of classrooms at the left end of the line, minus the required number of classrooms at the right end point plus 1. Then the statistical prefix and, if there is a certain point of the prefix and greater than the number of classrooms in the day, then there is a problem with the order, and then from the order number from small to large statistics in the order interval of the number of classrooms, save just can't meet the order of the test instructions, after not satisfied with the prefix and, The maximum number of statistics orders cannot exceed the previously saved order labels.

#include <cstdio> #define MAXN 1000005using namespace Std;typedef long long ll;struct t{LL D; int s,t;} A[maxn];int n,m; LL CL[MAXN]; LL SUM[MAXN];    LL t[maxn];int maxn;int pos = 123456789;int Main () {//freopen ("classroom.in", "R", stdin);    Freopen ("Classroom.out", "w", stdout);    scanf ("%d%d", &n,&m);    for (int i = 1; I <= n; i++) scanf ("%lld", &cl[i]);        for (int i = 1; I <= m; i++) {scanf ("%lld%d%d", &a[i].d,&a[i].s,&a[i].t);        if (a[i].t > Maxn) maxn = a[i].t;        T[A[I].S] + = A[I].D;        T[A[I].T] + = A[I].D;        if (T[a[i].s] > Cl[a[i].s]&&pos > i) {pos = i;        } if (t[a[i].t] > Cl[a[i].t]&&pos > i) {pos = i;        } Sum[a[i].s] + = A[I].D;    SUM[A[I].T+1]-= A[I].D;    } for (int i = 1; I <= maxn; i++) {Sum[i] + = sum[i-1]; } for (int i = 1; I <= n; i++) {if (Sum[i] > Cl[i])//RequiredExceed the number of classrooms {int temp = 0;                for (int j = 1; j <= M; j + +)//statistics within the order range and {if (J > Pos) break;//cannot exceed the maximum number of previous orders                if (a[j].s <= i&&a[j].t >= i) temp + = A[J].D;                if (temp > Cl[i]) {pos = j;//save maximum number of orders break;    }}}} if (pos = = 123456789) printf ("0\n");        else {printf (" -1\n");    printf ("%d\n", POS); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

NOIP2012 borrowed 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.