Pagini recente » Cod sursa (job #102295) | Cod sursa (job #2039561) | Cod sursa (job #338689) | Cod sursa (job #1402184) | Cod sursa (job #2651053)
//
// main.cpp
// curcubeu
//
// Created by Eusebiu Rares on 21/09/2020.
// Copyright © 2020 Eusebiu Rares. All rights reserved.
//
#include <iostream>
#include "fstream"
#include "algorithm"
template <typename T>
class InputReader {
private:
FILE *input_file ;
static const int SIZE = (1 << 17) ;
int point ;
char buffer[SIZE] ;
__attribute__ ( (always_inline)) void advance() {
++ point ;
if (point == SIZE) {
point = 0 ;
fread (buffer, SIZE, 1, input_file) ;
}
}
public:
InputReader() {}
InputReader (const char *file_name) {
input_file = fopen (file_name, "r") ;
point = 0 ;
fread (buffer, SIZE, 1, input_file) ;
}
__attribute__ ( (always_inline)) InputReader &operator >> (T &n) {
for (; !isdigit (buffer[point]) ; advance()) ;
n = 0 ;
for (; isdigit (buffer[point]) ; advance()) {
n = n * ( (1 << 3) + (1 << 1)) + buffer[point] - '0' ;
}
return *this ;
}
} ;
InputReader<int> input("curcubeu.in") ;
std::fstream output ("curcubeu.out", std::ios::out) ;
struct DC {
int c, poz ;
} ;
const int MV = 2005 ;
int n, job, dp[2][MV] ;
DC act[MV] ;
int main() {
int i, j, mx=-(1<<30), s ;
input >> n >> job ;
for (i = 1 ; i <= n ; ++ i) {
input >> act[i].poz >> act[i].c ;
}
std::sort(act + 1, act + n + 1, [](DC A, DC B) {
return A.poz < B.poz ;
}) ;
for (i = 1 ; i <= n ; ++ i) {
dp[0][i] = act[i].c - job ;
for (j = i - 1, s = act[i].c ; j >= 1 ; -- j) {
if (act[j].c >= act[i].c)
s += act[i].c ;
dp[0][i] = std::max(dp[0][i], s - (act[i].poz - act[j].poz + 1) * job) ;
}
for (j = i + 1, s = 0 ; j <= n ; ++ j) {
if (act[j].c >= act[i].c)
s += act[i].c ;
dp[1][i] = std::max(dp[1][i], s - (act[j].poz - act[i].poz) * job) ;
}
mx = std::max(mx, dp[0][i] + dp[1][i]) ;
}
output << mx ;
}