#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int n; long long pomoc; pair <long long, long long> tab[1000005]; long long result[1000005]; int main () { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%lld%lld", &tab[i].first, &tab[i].second); sort(tab, tab + n); for (int i = 0; i < n; ++i) for (long long j = i + 1; j > 0; --j) { pomoc = tab[i].first * (j - 1) + tab[i].second + result[j - 1]; if (pomoc > result[j]) result[j] = pomoc; } for (int i = 1; i <= n; ++i) printf("%lld\n", result[i]); 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 | #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int n; long long pomoc; pair <long long, long long> tab[1000005]; long long result[1000005]; int main () { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%lld%lld", &tab[i].first, &tab[i].second); sort(tab, tab + n); for (int i = 0; i < n; ++i) for (long long j = i + 1; j > 0; --j) { pomoc = tab[i].first * (j - 1) + tab[i].second + result[j - 1]; if (pomoc > result[j]) result[j] = pomoc; } for (int i = 1; i <= n; ++i) printf("%lld\n", result[i]); return 0; } |