Cod sursa(job #2759707)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 19 iunie 2021 23:15:16
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, c, dp[2005];

struct comanda{
    int t, p;
    bool operator < (comanda &c) const {
        return t < c.t;
    }
}v[2005];

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);
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        int x = v[i].p;
        memset(dp, 0, sizeof dp);
        for (int j = 1; j <= n; ++j){
            if (v[j].p >= x){
                dp[j] = max(dp[j], x);
                dp[j] = max(dp[j], x + dp[j - 1] -(v[j].t - v[j - 1].t) * c);
            }
            else{
                dp[j] = max(dp[j], dp[j - 1] - (v[j].t - v[j - 1].t) * c);
            }
            ans = max(ans, dp[j]);
        }
    }
    ans = max(0, ans - c);
    fout << ans;
    fin.close();
    fout.close();
    return 0;
}