Cod sursa(job #2697773)

Utilizator Asgari_ArminArmin Asgari Asgari_Armin Data 19 ianuarie 2021 16:10:00
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

const int NMAX = 2000;
struct lol{
  int x, y;
  bool operator < (const lol &shit) const {
    return x < shit.x;
  }
};
lol v[NMAX + 1];
int cost[NMAX + 1];

int main() {
  int n, i, j, sol, c;
  fin >> n >> c;
  for( i = 1; i <= n; ++i )
    fin >> v[i].x >> v[i].y;

  sort( v + 1, v + n + 1 );
  v[0].x = v[1].x - 1;
  sol = 0;
  for( i = 1; i <= n; ++i )
    for( j = 1; j <= n; ++j ){
      cost[j] = 0;
      if( v[i].y <= v[j].y )
        cost[j] = v[i].y;
      cost[j] = max(cost[j] - c, cost[j] + cost[j - 1] - (v[j].x - v[j - 1].x) * c);
      sol = max(sol, cost[j]);
    }
  fout << sol;
  return 0;
}