当先锋百科网

首页 1 2 3 4 5 6 7
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int maxres(vector<int>a){
    int buy=-pow(2,31);
    int sell=0;
    int buy1=-pow(2,31);
    int sell1=0;
    for(int i=0;i<a.size();i++){
        buy=max(buy,-a[i]);
        sell=max(sell,buy+a[i]);
        buy1=max(buy1,sell-a[i]);
        sell1=max(sell1,buy1+a[i]);
    }
    return sell1;
}


int main(){
    vector<int>arr={3,2,1,900,7,5,4,5};
    int res;
    res=maxres(arr);
    cout<<res<<endl;
    return 0;
}