Cod sursa(job #2293124)

Utilizator rares404AlShaytan - Balasescu Rares rares404 Data 30 noiembrie 2018 16:12:08
Problema Carnati Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 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) {
        (v[i].x - v[i - 1].x - 1) * c > profc ? profc = 0 : profc -= (v[i].x - v[i - 1].x - 1) * c ;
        profc += (v[i].y >= pret ? pret : 0) - c ;
        profm = MAX(profm, profc) ;
    }
    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;
}