Pagini recente » Cod sursa (job #1149130) | Cod sursa (job #2664943) | Cod sursa (job #2064556) | Cod sursa (job #488769) | Cod sursa (job #2926549)
#include <bits/stdc++.h>
using namespace std;
pair<int,int> a[2001], dp[2001];
int main(void){
ofstream cout("carnati.out");
ifstream cin("carnati.in");
int n,c;
cin >> n >> c;
for(int i = 1;i<=n;i++){
cin >> a[i].first >> a[i].second;
}
int maxmax = -1;
sort(a+1,a+n+1);
for(int i = 1;i<=n;i++){
/// vom lua fiecare pret in parte
int max1 = -1;
for(int j = 1;j<=n;j++){
dp[j].first = 0, dp[j].second = 0;
}
bool ok = 1;
for(int j = 1;j<=n;j++){
if(a[j].second >= a[i].second){ /// daca cumparatorul poate cumpara carnatul
if(ok){
dp[j].first = a[i].second;
dp[j].second = a[j].first;
}else{
if(dp[j-1].first + a[i].second - c * ((a[j].first - dp[j-1].second)+1) > a[i].second - c){
dp[j].first = dp[j-1].first + a[i].second;
dp[j].second = dp[j-1].second;
max1 = max(max1,dp[j].first - c * (a[j].first - dp[j].second + 1));
}else{
dp[j].first = a[i].second;
dp[j].second = a[j].first;
max1 = max(max1, dp[j].first - c);
}
}
ok = 0;
}else{
dp[j].first = dp[j-1].first;
dp[j].second = dp[j-1].second;
}
maxmax = max(maxmax, max1);
}
}
cout << maxmax;
}