Cod sursa(job #821949)

Utilizator andreidanAndrei Dan andreidan Data 22 noiembrie 2012 20:10:13
Problema Avioane Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
#include <algorithm>
#define val (( n + 1) - i)
typedef unsigned long long ull;

using namespace std;

int a[100005];

 int main(){
    int i ,j, n;
    ull sum = 0 , max = 0 , max2 = 0;

    ifstream f("avioane.in");
    ofstream g("avioane.out");

    f>>n;


    for( i = 1; i <= n ; ++ i )
        f>>a[i];

    sort( a + 1, a + n + 1);

    for( i = n ; i >1 ; --i ){
        sum = a[i] * val;
        for( j = 1 ; j <i; ++j ){
            max = a[j] * (i-j);

            if( sum + max > max2 ) max2 = sum + max;

        }
    }


    g<<max2;

    }