Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: compounding
- * created: 2024-12-10 14:46:52
- **/
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- #define f first
- #define s second
- #define yes cout << "YES" << endl
- #define no cout << "NO" << endl
- #define endl "\n"
- const int mod = 1000000007;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- const int N = (int)1e5 + 5;
- int a[N], maxleft[N], maxright[N], minleft[N], minright[N];
- void solve()
- {
- int n, p, q, r;
- cin >> n >> p >> q >> r;
- for (int i = 1; i <= n; i++)
- {
- cin >> a[i];
- }
- minleft[1] = a[1], maxleft[1] = a[1];
- for (int i = 2; i <= n; i++)
- {
- minleft[i] = min(minleft[i - 1], a[i]);
- maxleft[i] = max(maxleft[i - 1], a[i]);
- }
- minright[n] = a[n], maxright[n] = a[n];
- for (int i = n - 1; i >= 1; i--)
- {
- minright[i] = min(minright[i + 1], a[i]);
- maxright[i] = max(maxright[i + 1], a[i]);
- }
- int ans = LLONG_MIN;
- for (int i = 1; i <= n; i++)
- {
- int leftval = (p < 0) ? 1LL * minleft[i] * p : 1LL * maxleft[i] * p;
- int rightval = (r < 0) ? 1LL * minright[i] * r : 1LL * maxright[i] * r;
- ans = max(ans, leftval + 1LL * a[i] * q + rightval);
- }
- cout << ans << endl;
- return;
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment