比赛 进阶指南第0章测试 评测结果 WWWWWWWAWWWWWWWWWWWW
题目名称 借教室 最终得分 5
用户昵称 赵飞羽 运行时间 1.754 s
代码语言 C++ 内存使用 9.43 MiB
提交时间 2026-03-14 09:34:49
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e6 + 10;
int n, m, r[N], d[N], s[N], t[N], c[N];

bool check(int x) {
	for (int i = 1; i <= n; i++) c[i] = 0;
	for (int i = 1; i <= x; i++) c[s[x]] += d[x], c[t[x]+1] -= d[x];
	for (int i = 1; i <= x; i++) {
		c[i] += c[i-1];
		if (c[i] > r[i]) return false;
	}
	return true;
}

signed main() {
	freopen("classrooms.in", "r", stdin);
	freopen("classrooms.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> r[i];
	for (int i = 1; i <= m; i++) cin >> d[i] >> s[i] >> t[i];
	int l = 1, r = n;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	if (l == n) cout << 0;
	else cout << -1 << "\n" << l + 1;
	return 0;
}