Advertisement
7oSkaaa

F - Pure Oxgen

Aug 1st, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define cin(vec) for(auto& i : vec) cin >> i
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  8. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define fixed(n) fixed << setprecision(n)
  11. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  12. #define fill(vec, value) memset(vec, value, sizeof(vec));
  13. #define Num_of_Digits(n) ((int)log10(n)+1)
  14. #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
  15. #define all(vec) vec.begin(),vec.end()
  16. #define rall(vec) vec.rbegin(),vec.rend()
  17. #define sz(x) int(x.size())
  18. #define TC int t; cin >> t;   while(t--)
  19. #define fi first
  20. #define se second
  21. #define Pair pair < int, int >
  22. #define ll long long
  23. #define ull unsigned long long
  24. #define Mod  1'000'000'007
  25. #define OO 2'000'000'000
  26. #define EPS 1e-9
  27. #define PI acos(-1)
  28.  
  29. void AhMeD_HoSSaM(){
  30.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31.   #ifndef ONLINE_JUDGE
  32.     //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33.   #endif
  34.   freopen("oxy.in", "r", stdin);
  35. }
  36.  
  37. int main(){
  38.   AhMeD_HoSSaM();
  39.   int n;
  40.   cin >> n;
  41.   vector < int > nums(n);
  42.   cin(nums);
  43.   vector < int > Min(n + 2, OO), Max(n + 2, -OO);
  44.   for(int i = 1; i <= n; i++) Min[i] = min(Min[i - 1], nums[i - 1]);
  45.   for(int i = n; i >= 1; i--) Max[i] = max(Max[i + 1], nums[i - 1]);
  46.   int buy = -1, sell = -1, cost = -1, Max_Prof = -OO;
  47.   for(int i = 1; i <= n; i++){
  48.     if(Max_Prof < Max[i] - Min[i]) buy = Min[i], sell = Max[i], Max_Prof = Max[i] - Min[i];
  49.   }
  50.   if(Max_Prof <= 0) cout << -1 << "\n";
  51.   else {
  52.     int first_idx = find(all(nums), buy) - nums.begin(), last_idx = -1;
  53.     for(int i = first_idx; i < n; i++){
  54.       if(nums[i] == sell){
  55.         last_idx = i;
  56.         break;
  57.       }
  58.     }
  59.     cout << first_idx + 1 << " " << last_idx + 1 << " " << Max_Prof << "\n";
  60.   }
  61.   Time
  62.   return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement