Pagini recente » Cod sursa (job #2377753) | Cod sursa (job #2767272) | Cod sursa (job #1996035) | Cod sursa (job #1183242) | Cod sursa (job #2768105)
#include <fstream>
#include <algorithm>
using namespace std;
int n, c;
pair<int, int> v[2001];
void read() {
int i;
ifstream f("carnati.in");
f >> n >> c;
for (i = 1; i <= n; i++)
f >> v[i].first >> v[i].second;
f.close();
}
int Maxglobal;
bool csort(pair<int, int> a, pair<int, int> b) {
if (a.first < b.first)
return 1;
return 0;
}
void solve() {
int i, sum, Max, j, nr, st;
sort(v + 1, v + n + 1, csort);
for (i = 1; i <= n; i++) {
sum = 0;
Max = 0;
st = 1;
nr = 0;
for (j = 1; j <= n; j++) {
nr += (v[j].second >= v[i].second);
sum = -(v[j].first - v[st].first + 1) * c + nr * v[i].second;
if (sum > Max)
Max = sum;
if (sum < 0) {
sum = 0;
st = j + 1;
nr = 0;
}
}
if (Max > Maxglobal)
Maxglobal = Max;
}
}
void output() {
ofstream g("carnati.out");
g << Maxglobal;
g.close();
}
int main() {
read();
solve();
output();
return 0;
}