Cod sursa(job #629141)

Utilizator ZexonAvramita Teodor Zexon Data 2 noiembrie 2011 18:19:09
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
#include <string>
# include <cstdlib>
#include <algorithm>
using namespace std;
ifstream in("carnati.in");
ofstream out("carnati.out");
int clienti;
int paguba;
pair <int,int> v[2001];

int profit(int pret)
{
    int sc,smax,prc;
    sc=smax=0;
    for (int i =1;i<=clienti;i++)

    {
        if(v[i].second>=pret)
            prc=pret-paguba;
        else prc = -paguba;
        sc= max(sc - (v[i].first-v[i-1].first-1)*paguba,0) +prc;
        if (sc>smax) smax =sc;
    }
    return smax;
}

int main()

{
    int hellYeha=0;
    int imholding;
    string tmp;
    in>>tmp;
    clienti = atoi(tmp.c_str());
    in>>tmp;
    paguba = atoi(tmp.c_str());
     for (int i=1; i<=clienti ;i++ )
        {
            in>>tmp;
            v[i].first = atoi(tmp.c_str());
            in>>tmp;
            v[i].second = atoi(tmp.c_str());
        }
    sort(&v[1],&v[clienti+1]);
    v[0].first = -1000;
    for (int i=0; i<clienti ;i++ )
    {
       imholding = profit(v[i].second);
       if (imholding > hellYeha)
       hellYeha = imholding;
    }
    out<<hellYeha;
}