1 条题解
-
1
#include<iostream> #include<cstring> using namespace std; typedef long long LL; const int N = 1e6 + 10; LL a[N], d[N], s[N], t[N], b[N]; int n, m; bool check(int u) { memset(b, 0, sizeof(b)); for (int i = 1; i <= u; ++ i) { b[s[i]] += d[i]; b[t[i] + 1] -= d[i]; } for (int i = 1; i <= n; ++ i) { b[i] += b[i - 1]; if (b[i] > a[i]) return false; } return true; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]); for (int i = 1; i <= m; ++ i) scanf("%d%d%d", &d[i], &s[i], &t[i]); int l = 0, r = m; while (l < r) { int mid = (l + r + 1) >> 1; if (check(mid)) l = mid; else r = mid - 1; } if (l == m) cout << 0 << endl; else { cout << -1 << endl; cout << r + 1 << endl; } return 0; }
- 1
信息
- ID
- 5499
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 20
- 已通过
- 6
- 上传者