#include <iostream>
#include <algorithm>
using namespace std;
const int N=1000000;
long long w1[N], w2[N];
struct S
{
long long coNoc, pocz;
bool operator<(const S &drugi) const
{
return coNoc<drugi.coNoc;
}
} ab[N];
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
for (int i=0; i<n; ++i)
cin>>ab[i].coNoc>>ab[i].pocz;
sort(ab, ab+n);
long long *ost=w1, *nast=w2;
ost[0]=ab[0].pocz;
for (int i=1; i<n; ++i)
{
S &nowy=ab[i];
nast[0]=max(ost[0], ab[i].pocz);
for (int j=1; j<i; ++j)
nast[j]=max(ost[j], ost[j-1]+nowy.pocz+nowy.coNoc*j);
nast[i]=ost[i-1]+nowy.pocz+nowy.coNoc*i;
swap(ost, nast);
}
for (int i=0; i<n; ++i)
cout<<ost[i]<<'\n';
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <algorithm> using namespace std; const int N=1000000; long long w1[N], w2[N]; struct S { long long coNoc, pocz; bool operator<(const S &drugi) const { return coNoc<drugi.coNoc; } } ab[N]; int main() { ios_base::sync_with_stdio(false); int n; cin>>n; for (int i=0; i<n; ++i) cin>>ab[i].coNoc>>ab[i].pocz; sort(ab, ab+n); long long *ost=w1, *nast=w2; ost[0]=ab[0].pocz; for (int i=1; i<n; ++i) { S &nowy=ab[i]; nast[0]=max(ost[0], ab[i].pocz); for (int j=1; j<i; ++j) nast[j]=max(ost[j], ost[j-1]+nowy.pocz+nowy.coNoc*j); nast[i]=ost[i-1]+nowy.pocz+nowy.coNoc*i; swap(ost, nast); } for (int i=0; i<n; ++i) cout<<ost[i]<<'\n'; return 0; } |
English