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