Cod sursa(job #2706123)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 13 februarie 2021 21:51:22
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#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';
}