还有个问题,我的代码在我的电脑上跑出来是错的,在我舍友电脑上跑出来就是对的
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1000010;
int n, m; //天数和订单数量
long long int a[N], b[N]; //可用于租借的教室数量, 差分数组
long long int d[N], s[N], t[N]; // 租借数量, 开始, 结束
bool judge = true;
long long int tmp = 0;
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= m; i ++) cin >> d[i] >> s[i] >> t[i];
int l = 0, r = m;
while(l < r)
{
memset(b, 0, sizeof b);
int mid = l + r >> 1;
for(int i = 1; i <= mid; i ++)
{
b[s[i]] += d[i];
b[t[i] + 1] -= d[i];
}
long long int sum = 0;
judge = true;
for(int i = 1; i <= n; i ++)
{
sum += b[i];
//cout << "sum:" << sum << endl;
if(sum > a[i]) judge = false;
}
//cout << l << " " << r << endl;
if(!judge) r = mid;
else l = mid + 1;
}
memset(b, 0, sizeof b);
for(int i = 1; i <= r; i ++)
{
b[s[i]] += d[i];
b[t[i] + 1] -= d[i];
}
int sum = 0;
judge = true;
for(int i = 1; i <= n; i ++)
{
sum += b[i];
if(sum > a[i]) judge = false;
}
//cout << "r:" << r << endl;
if(judge) cout << "0";
else cout << "-1" << endl << r;
}