Cod sursa(job #2650358)

Utilizator ptudortudor P ptudor Data 18 septembrie 2020 14:56:50
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.01 kb
#include<bits/stdc++.h>
#define fore(start,i,end) for(int i = start; i <= end; i++)
#define dbg(x)  #x << "=" << x << " "
#define dbg2(x,y)  "{" << x << "," << y << "} "
#define dbg3(x,y,k) "{" << x << "," << y << "," << k << "} "
#define dbg4(x,y,k,j) "{" << x << "," << y << "," << k << " , " << j << "} "

#define ll long long
#define f1 first
#define f2 second
#define inf 1000000005
#define debug_st(st) if (true) {cout << #st << " : "; stack<int> s123; while (!s123.empty()) cout << s123.top() << " ", s123.pop(); cout << "\n";}
#define debug_a(a,n) cout << #a << " : "; for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << "\n";
#define debug_m(a,n,m) cout << #a << " :\n"; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) cout << a[i][j] << " "; cout << "\n"; }cout << "\n";
#define debug_v(v) cout << #v << " : "; for(auto k : v) cout << k << " "; cout << "\n";
#define debug_s(s) cout << #s << " : "; for (auto k : s) cout << k < " "; cout << "\n";
#define debug_s2(s) cout << #s << " : "; for(auto k : s) cout << dbg2((*k).first,(*k).second); cout << "\n";
#define nmax 2005



using namespace std;

ifstream in("carnati.in");
ofstream out("carnati.out");
int maxpoz,n,v[nmax],c;
pair<int,int> a[nmax];
int find_prof_max(int pret)
{
    int fin = 0,val,s = 0;
    //cout << dbg(pret) << "\n";
    //debug_a(v , maxpoz);
    for (int i = 0; i <= maxpoz; i++)
    {
        val = v[i] * pret;
        val -= c;
        s += val;
        if (s < 0)s = 0;

        fin = max(fin , s);
    }
    //cout << "VAL FIN = " << fin << "\n\n\n";
    return fin;
}
int main()
{int i,ans = 0;
    in >> n >> c;
    for (i = 1; i <= n; i++)
    {
        int t,p;
        in >> t >> p;
        a[i] = {p , t};
        maxpoz = max(maxpoz , t);
    }
    sort (a + 1, a + 1 + n);

    for (i = n; i >= 1; i--)
    {
        int pret = a[i].first;
        v[a[i].second]++;

        int sol = find_prof_max(pret);

        ans = max(sol , ans);
    }

    out << ans << "\n";

}