
贪心、树状数组,我看题解,有些大佬用的线段树、树状数组(其实是自己功力还不够)。
杀鸡蔫用牛刀,对于蒟蒻的我,更熟悉纯模拟+贪心策略+差分。题目原文请移步下面的链接
贪心、树状数组普及-#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
void best_coder() {
int n;
scanf("%d", &n);
int ans = 0;
vector<int> a(n);
int t = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
if (a[i] > t) {
ans += a[i] - t;
}
t = a[i];
}
printf("%d", ans);
}
void happy_coder() {
}
int main() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// 小码匠
best_coder();
// 最优解
// happy_coder();
// 返回
return 0;
}END