Advertisement
Imran1107048

Maximum Profit

Jun 22nd, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int n;
  6. scanf("%d",&n);
  7. long long int profit = -99999999999, max = 999999999999;
  8. for(int i=0;i<n;i++){
  9. long long int x;
  10. scanf("%lld",&x);
  11. if(x-max > profit)
  12. profit = x-max;
  13. if(max > x)
  14. max = x;
  15. }
  16. printf("%lld\n",profit);
  17. return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement