提交时间:2023-12-16 09:20:47

运行 ID: 116219

#include<bits/stdc++.h> using namespace std; int main() { int n,prices[1005]; cin>>n; int buy[1005]={0},sell[1005]={0},freeze[1005]={0}; for(int i=0;i<n;i++) cin>>prices[i]; buy[0]=-prices[0]; for(int i=1;i<n;i++) { buy[i]=max(buy[i-1],freeze[i-1]-prices[i]); sell[i]=max(sell[i-1],buy[i-1]+prices[i]); freeze[i]=max(freeze[i-1],sell[i-1]); } cout<<max(sell[n-1],freeze[n-1]); }