Pagini recente » Cod sursa (job #427515) | Cod sursa (job #3278865) | Cod sursa (job #700276) | Cod sursa (job #3161913) | Cod sursa (job #2706123)
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
const int INF = 1e18L;
void max_self(int &a, int b) {
a = max(a, b);
}
int32_t main(){
int N, C;
fin >> N >> C;
vector<pair<int,int>> people(N);
int dim = 0;
for(auto &p : people) {
fin >> p.first >> p.second;
max_self(dim, p.first);
}
int ans = -INF;
for(const auto &p : people) {
int price = p.second;
vector<int> a(dim + 1, -C);
for(const auto &x : people)
if(x.second >= price)
a[x.first] += price;
int sum_max = -INF, sum = 0;
for(const int &x : a) {
if(sum < 0)
sum = x;
else
sum += x;
sum_max = max(sum_max, sum);
}
ans = max(ans, sum_max);
}
fout << ans << '\n';
}