Cod sursa(job #2854680)

Utilizator Casian_doispeChiriac Casian Casian_doispe Data 21 februarie 2022 17:31:29
Problema Parantezare optima de matrici Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.17 kb
#include <fstream>
#include <deque>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>

#define MOD 104659

using namespace std ;

ifstream cin ("podm.in") ;
ofstream cout ("podm.out") ;

int n ;

long long v[509] ;

void remov(int poz)
{
    for(int f = poz ; f <= n + 1 ; f ++)
        v[f] = v[f + 1] ;

    n -- ;
}

int main()
{
    cin >> n ;

    for(int f = 1 ; f <= n + 1 ; f ++)
        cin >> v[f] ;

    long long s = 0 ;

    for(int f = 1 ; f <= n + 1 ; f ++)
    {
        int pozmax = 2 ;

        for(int f = 2 ; f <= n ; f ++)
            if(v[f] > v[pozmax])pozmax = v[f] ;

        s += v[pozmax] * v[pozmax - 1] * v[pozmax + 1] ;

        remov(pozmax) ;
    }

    cout << s ;

    return 0 ;
}
/*
17
12.000000 1.000000
3.000000 -6.000000
6.000000 7.000000
-8.000000 12.000000
-12.000000 -11.000000
-6.000000 -3.000000
3.000000 10.000000
-10.000000 0.000000
7.000000 -13.000000
-14.000000 -6.000000
-12.000000 -7.000000
12.000000 -1.000000
-3.000000 -9.000000
11.000000 7.000000
1.000000 10.000000
6.000000 -5.000000
3.000000 11.000000
*/