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没有效果
- 下一篇: Objective-C设计模式——生成器