Cod sursa(job #2293144)

Utilizator rares404AlShaytan - Balasescu Rares rares404 Data 30 noiembrie 2018 16:33:10
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <bits/stdc++.h>
#define int long long
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
const int VM(2005) ;
int n, c, ans ;
struct DC {
    int x, y ;
    bool operator < (const DC& other) const {
        return this->x < other.x;
    }
}v[VM];
int Baga(int pret) {
    int profc(0), profm(1 << 31) ;
    register int i ;
    for (i = 1 ; i <= n ; ++ i) {
        profc = MAX(profc - (v[i].x - v[i - 1].x) * c, 0);
        if(pret <= v[i].y)
            profc += pret;
        profm = MAX(profm, profc - c);
    }
    return profm ;
}

int32_t main() {
    freopen("carnati.in", "r", stdin) ;
    freopen("carnati.out", "w", stdout) ;
    register int i ;
    scanf("%lld %lld", &n, &c) ;
    for (i = 1 ; i <= n ; ++ i)
        scanf("%lld %lld", &v[i].x, &v[i].y) ;
    std::sort(v + 1,v + 1 + n) ;
    for (i = 1 ; i <= n ; ++ i)
        ans = MAX(ans, Baga(v[i].y)) ;
    printf("%lld", ans) ;
    return 0;
}