# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466990 | AMO5 | Discharging (NOI20_discharging) | C++17 | 0 ms | 0 KiB |
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;
#define fi first
#define se second
#define ld long double
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define dbg if(0)
#define BUG(x) dbg cerr << (#x) << " is " << (x) << endl
const int mxn = (int)1e6+5;
const int64_t inf = 5e18;
//subtask 2
void solve(){
int n; cin>>n;
vector<int64_t>a(n);
for(auto &x:a)
{
cin>>x;
}
vector<int64_t>dp(n);
for(int i=0; i<n; i++){
dp[i] = in#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ld long double
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define dbg if(0)
#define BUG(x) dbg cerr << (#x) << " is " << (x) << endl
const int mxn = (int)1e6+5;
const int64_t inf = 5e18;
//subtask 2
void solve(){
int n; cin>>n;
vector<int64_t>a(n);
for(auto &x:a)
{
cin>>x;
}
vector<int64_t>dp(n);
for(int i=0; i<n; i++){
dp[i] = inf;
for(int j=i; j>=0; j--){
int len = n-j;
int64_t curr = (int64_t)1*len*(a[i]) + (j>0?dp[j]:(int64_t)0);
dbg cerr<<i<<" "<<j<<" "<<curr<<"\n";
dp[i]=min(dp[i],curr);
}
}
cout<<dp.back()<<"\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int t=1; cin>>t; while(t--)
solve();
return 0;
}
f;
for(int j=i; j>=0; j--){
int len = n-j;
int64_t curr = (int64_t)1*len*(a[i]) + (j>0?dp[j]:(int64_t)0);
dbg cerr<<i<<" "<<j<<" "<<curr<<"\n";
dp[i]=min(dp[i],curr);
}
}
cout<<dp.back()<<"\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int t=1; cin>>t; while(t--)
solve();
return 0;
}