parent
c1e6795d43
commit
382b37c11e
@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1e6 + 10;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
int n, a[N], s[N], ans[N];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i], s[i] = s[i - 1] + a[i]; // 前缀和
|
||||
|
||||
int mi = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans[i] = s[i] - mi;
|
||||
mi = min(mi, s[i]);
|
||||
}
|
||||
int res = -INF;
|
||||
for (int i = 1; i <= n; i++) res = max(res, ans[i]);
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 1010;
|
||||
int b[N][N], s[N][N];
|
||||
int n, m;
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
while (m--) {
|
||||
// 从0开始构建差分数组
|
||||
int x1, y1, x2, y2;
|
||||
cin >> x1 >> y1 >> x2 >> y2;
|
||||
b[x1][y1] += 1; // 进行子矩阵的加减,差分
|
||||
b[x2 + 1][y1] -= 1;
|
||||
b[x1][y2 + 1] -= 1;
|
||||
b[x2 + 1][y2 + 1] += 1;
|
||||
}
|
||||
// 还原为原始数组
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
s[i][j] = b[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1]; // 把之前的加减结果进行求和
|
||||
printf("%d ", s[i][j]); // 注意输出格式,每个数带一个空格
|
||||
}
|
||||
printf("\n"); // 结束一行的输出输出一个换行符号
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue