Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
111296 CBCode 买卖股票的最佳时机 C++ 通过 100 0 MS 252 KB 592 2023-11-19 17:16:38

Tests(3/3):


#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() typedef long long ll; int main() { int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } ll ans = 0; int status = 0, pos = 0; for(int i = 0; i < n; i++) { if(status == 1 && a[i] >= a[i-1]) { ans += a[i]-a[pos]; status = 0; } if(status == 0 && i < n-1 && a[i]<a[i+1]) { status = 1; pos = i; } } cout << ans << '\n'; return 0; }


测评信息: