yifan的数组
yifan的数组
时间限制: 1 Sec 内存限制: 128 MB提交: 159 解决: 47
[提交][状态]
题目描述
给你一个数组,初始值都是0,然后有N个操作,每次在一段区间L,R上加W,操作完后,求出这个数组中最大值是多少?
输入
多组样例,一个数字N表示N个操作,接下来N个数字L,R, W,表示给区间L,R加W,(1 <= L, R, W <= 100000。0 <= N <= 100000)
输出
一个数字代表答案
样例输入
3 1 2 1 1 3 2 1 3 4 4 1 1 2 2 2 4 3 3 1 4 4 5 0样例输出
7 5 0这题要好好的记录一下,也可以这么玩儿~
(为什么听过一遍题解,还和第一次见差不多~ #include<iostream> #include<cstring> #include<cstring>using namespace std;#define N 100010int main() {int n, l, r, w, a[N];while(cin >> n){int ans = 0, maxx = 0;;memset(a, 0, sizeof(a));if(n == 0){cout << n << endl;break;}for(int i = 0; i < n; i++){cin >> l >> r >> w;ans = ans > r ? ans : r;a[l] += w;a[r+1] -= w;}for(int i = 1; i <= ans; i++){a[i] += a[i-1];if(a[i] > maxx)maxx = a[i];}cout << maxx << endl;}return 0; }
转载于:https://www.cnblogs.com/Tinamei/p/4661959.html
总结
- 上一篇: 解决margin-top没有效果
- 下一篇: java.math.BigDecimal