Cod sursa(job #2983736)

Utilizator NarcisMMic Narcis NarcisM Data 22 februarie 2023 21:13:07
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int n, c, dp[2002], sol;
struct persoana{
    int t, p;
}v[2001];
bool cmp(persoana a, persoana b){
    return a.t < b.t;
}
int main(){
    fin >> n >> c;
    for(int i = 1; i <= n; i++)
        fin >> v[i].t >> v[i].p;
    sort(v + 1, v + n + 1, cmp);
    v[0].t = v[1].t - 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            dp[j] = 0;
            if(v[i].p <= v[j].p)
                dp[j] = v[i].p;
            dp[j] = max(dp[j] + dp[j - 1] - (v[j].t - v[j - 1].t) * c, dp[j] - c);
            sol = max(dp[j], sol);
        }
    }
    fout << sol;
    return 0;
}