Submission #288485

# Submission time Handle Problem Language Result Execution time Memory
288485 2020-09-01T14:20:30 Z Blagojce Discharging (NOI20_discharging) C++11
0 / 100
1000 ms 8636 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
 
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 2e5+5;
 
const ll A = 911382323;
const ll B = 972663749;



void solve(){
	int n;
	cin >> n;
	ll a[n];
	fr(i, 0, n){
		cin >> a[i];
	}
	
	ll dp[n+1];
	dp[n] = 0;
	for(int i = n-1; i >= 0; i --){
		
		
		dp[i] = a[i]*(n-i);
		ll mi = dp[i+1];
		fr(j, i+1, n){
			if(a[j] >= a[i]) break;
			mi = min(dp[j+1], mi);
		}
		dp[i] += mi;
	
	}
	
	ll mx = 0;
	ll ans = inf;
	fr(i, 0, n){
		mx = max(mx, a[i]);
		ans = min(ans, dp[i+1]+mx*n); 
	}
	cout<<ans<<endl;
	
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	//cin >> tc;
	while(tc--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 8636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -