This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vp;
#define nl "\n"
#define fr first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
#define fur(i, a, b) for(ll i = a; i <= b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= b; --i)
#define pv(x) for(auto k : x){cout << k << " ";} cout << nl
const ll inf = 1e17;
struct dt{
ll cost, li, wt;
dt(){
cost = li = wt = inf;
}
void print(){
cout << cost << ' ' << li << ' ' << wt << nl;
}
};
ll n, sz;
vl t, st;
ll maxr(ll l, ll r, ll k, ll kl, ll kr){
if (kl > r || kr < l)
return 0;
if (kl >= l && kr <= r)
return st[k];
ll m = (kl + kr)/2;
return max(maxr(l, r, 2 * k, kl, m), maxr(l, r, 2 *k + 1, m + 1, kr));
}
void solve(){
//cout << "n = " << n << nl;
ll dp[n + 1];
dp[0] = 0;
//dp[1] = t[1];
fur(x, 1, n){
dp[x] = inf;
ruf(i, x, 1)
dp[x] = min(dp[x], dp[i - 1] + (t[x] * (n - i + 1)));
}
cout << dp[n] << nl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("/home/compslab9/Desktop/Abhineet/cpp/input.txt", "r", stdin);
freopen("/home/compslab9/Desktop/Abhineet/cpp/output.txt", "w", stdout);
#endif
cin >> n;
t.resize(n + 1);
t[0] = 0;
fur(i, 1, n)
cin >> t[i];
sz = n;
while(__builtin_popcountll(sz) != 1)
sz++;
st.resize(2*sz, 0);
fur(i, 0, n - 1)
st[i + sz] = t[i + 1];
ruf(i, sz - 1, 1)
st[i] = max(st[2 * i], st[2*i + 1]);
solve();
return 0;
}
Compilation message (stderr)
Discharging.cpp: In function 'int main()':
Discharging.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen("/home/compslab9/Desktop/Abhineet/cpp/input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Discharging.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen("/home/compslab9/Desktop/Abhineet/cpp/output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |