Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
191151252 Contestant:
namanbansal013
1787C - 37 C++17 (GCC 7-32) Accepted 342 ms 26576 KB 2023-01-29 19:37:42 2023-01-29 20:58:52
→ Source
//My YouTube channel: https://www.youtube.com/namanbansal

#include <bits/stdc++.h>
using namespace std;

#define watch(x) cout << (#x) << " = " << (x) << endl
#define MOD 1000000007

long long a[200005], x[200005], y[200005], dp[200005][2];
long long n;

long long solve(long long index, long long next, int turn)  {
    if(index == n)  {
        return next * a[n];
    }
    if(dp[index][turn] != -1)   {
        return dp[index][turn];
    }
    
    long long ans = (next * x[index]) + solve(index+1, y[index], 0);
    long long ans1= (next * y[index]) + solve(index+1, x[index], 1);
    return dp[index][turn] = min(ans, ans1);
}

int main()  {
    long long t;
    cin >> t;
    while(t--)  {
        long long s;
        cin >> n >> s;
        for(long long i = 1; i <= n; i++)  {
            cin >> a[i];
            dp[i][0] = -1;
            dp[i][1] = -1;
        }
        for(long long i = 2; i <= (n-1); i++) {
            if(a[i] >= 2*s) {
                x[i] = s;
                y[i] = a[i] - s;
            } else if(a[i] >= s && a[i] < (2*s))    {
                x[i] = a[i] - s;
                y[i] = s;
            } else {
                x[i] = 0;
                y[i] = a[i];
            }
        }
        long long ans = (a[1] * x[2]) + solve(3, y[2], 0);
        long long ans1 = (a[1] * y[2]) + solve(3, x[2], 1);
        
        cout << min(ans, ans1) << "\n";
    }
    return 0;
} 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details