Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Profit Maximization:
- int ans = 0;
- int buy = v[0];
- for (int i = 1; i < n; i++)
- {
- ans = max(ans, v[i] - buy);
- buy = min(buy, v[i]);
- }
- return and;
- Profit Maximization - Extended
- int ans = 0;
- int buy = v[0];
- for (int i = 1; i < n; i++)
- {
- if(v[i] > v[i-1])ans += v[i]-v[i-1];
- }
- return and;
- Profit Model for John:
- string ans;
- for (int test = 0; test < d; test++){
- int target = profit[test];
- int f = 1;
- string res;
- int id1 = 0, id2 = 100000000;
- for (int i = 0; i < n; i++)
- {
- for (int j = i+1; j < n ; j++){
- if(price[j] - price[i] == target){
- if(id2 - id1 > j - i){
- res = to_string(i + 1) + ' ' + to_string(j + 1);
- f = 0;
- id1 = i;
- id2 = j;
- }
- }
- }
- }
- if(f)
- res = to_string(-1);
- if(ans.size())
- ans += ',' + res;
- else
- ans = res;
- }
- return ans;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement