#include <iostream>
#include<vector>
using namespace std;
class Solution {
public:
int maxProfit(vector<int>& prices) {
int buy=prices[0];
int max_profit=0;
// Run the loop for the given equation
for (int i = 1; i < prices.size(); ++i) {
// If the current price is higher than the previous day's price,
// we can buy and sell on the same day to make a profit.
if (prices[i] > prices[i - 1]) {
max_profit += prices[i] - prices[i - 1];
}
}
return max_profit;
}
};
int main() {
// your code goes here
Solution s1;
vector<int> v1={7,1,5,3,6,4};
int maxProfit1=s1.maxProfit(v1);
cout<<maxProfit1;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogY2xhc3MgU29sdXRpb24gewogcHVibGljOgogICAgaW50IG1heFByb2ZpdCh2ZWN0b3I8aW50PiYgcHJpY2VzKSB7CiAgICAgaW50IGJ1eT1wcmljZXNbMF07CiAgICAgaW50IG1heF9wcm9maXQ9MDsKICAgICAvLyBSdW4gdGhlIGxvb3AgZm9yIHRoZSBnaXZlbiBlcXVhdGlvbgogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBwcmljZXMuc2l6ZSgpOyArK2kpIHsKICAgICAgICAvLyBJZiB0aGUgY3VycmVudCBwcmljZSBpcyBoaWdoZXIgdGhhbiB0aGUgcHJldmlvdXMgZGF5J3MgcHJpY2UsCiAgICAgICAgLy8gd2UgY2FuIGJ1eSBhbmQgc2VsbCBvbiB0aGUgc2FtZSBkYXkgdG8gbWFrZSBhIHByb2ZpdC4KICAgICAgICBpZiAocHJpY2VzW2ldID4gcHJpY2VzW2kgLSAxXSkgewogICAgICAgICAgICBtYXhfcHJvZml0ICs9IHByaWNlc1tpXSAtIHByaWNlc1tpIC0gMV07CiAgICAgICAgfQogICAgfQogICAgCiAgICAgIHJldHVybiBtYXhfcHJvZml0OwogICAgIH0KICAgIAogICAgICAgIAogICAgfTsKCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJU29sdXRpb24gczE7Cgl2ZWN0b3I8aW50PiB2MT17NywxLDUsMyw2LDR9OwoJaW50IG1heFByb2ZpdDE9czEubWF4UHJvZml0KHYxKTsKCWNvdXQ8PG1heFByb2ZpdDE7CglyZXR1cm4gMDsKfQ==