Cod sursa(job #2129504)

Utilizator liviu2000Dragomirescu Liviu liviu2000 Data 12 februarie 2018 21:10:56
Problema Carnati Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("carnati.in") ;
ofstream fout("carnati.out") ;

int n , k ;
pair<int,int> om[2001] ;

int main()
{
    int i , j , cost , best , inc , ct ;
    fin >> n >> k ;
    for ( i = 1 ; i <= n ; i++ )
        fin >> om[i].first >> om[i].second ;
    best = -0x3f3f3f3f ;
    for ( i = 1 ; i <= n ; i++ )
    {
        cost = om[i].second ;
        ct = 0;
        inc = 1 ;
        for ( j = 1 ; j <= n ; j++ )
        {
            if ( om[j].second >= cost )
                ct++ ;
            if ( cost*ct < (abs(om[j].first-om[inc].first)+1)*k )
            {
                inc = j+1;
                ct = 0 ;
            }
            else
            {
                if ( cost*ct - (abs(om[j].first-om[inc].first)+1)*k > best )
                {
                    best = cost*ct-(abs(om[j].first-om[inc].first)+1)*k ;
                }
            }
        }
    }
    fout << best ;
}