// if you have a lot of women always physically climbing on your back then have i got a code for you #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <cstring> #include <cassert> using namespace std; #define rep(i,a,n) for (int i=a;i<(n);i++) #define per(i,a,n) for (int i=(n)-1;i>=(a);i--) template<typename T> ostream& operator<<(ostream& s, vector<T> t) {rep(i, 0, t.size()) s << (i ? " " : "") << t[i]; return s;} template<typename T> istream& operator>>(istream& s, vector<T> &t) {rep(i, 0, t.size()) s >> t[i]; return s;} typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<pair<ll, ll>> raw(n); rep(i, 0, n) cin >> raw[i].first >> raw[i].second; sort(raw.begin(), raw.end()); vector<ll> a(n), b(n); rep(i, 0, n) a[i] = raw[i].first, b[i] = raw[i].second; vector<ll> dp0(n + 1, 0), dp1(n + 1); rep(j, 0, n) { rep(i, 0, n) dp1[i] = 0; rep(i, 0, n) { dp1[i + 1] = max(dp1[i], dp0[i] + j * a[i] + b[i]); } //cout << dp1 << endl; cout << dp1[n] << endl; swap(dp0, dp1); } }
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 41 42 | // if you have a lot of women always physically climbing on your back then have i got a code for you #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <cstring> #include <cassert> using namespace std; #define rep(i,a,n) for (int i=a;i<(n);i++) #define per(i,a,n) for (int i=(n)-1;i>=(a);i--) template<typename T> ostream& operator<<(ostream& s, vector<T> t) {rep(i, 0, t.size()) s << (i ? " " : "") << t[i]; return s;} template<typename T> istream& operator>>(istream& s, vector<T> &t) {rep(i, 0, t.size()) s >> t[i]; return s;} typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<pair<ll, ll>> raw(n); rep(i, 0, n) cin >> raw[i].first >> raw[i].second; sort(raw.begin(), raw.end()); vector<ll> a(n), b(n); rep(i, 0, n) a[i] = raw[i].first, b[i] = raw[i].second; vector<ll> dp0(n + 1, 0), dp1(n + 1); rep(j, 0, n) { rep(i, 0, n) dp1[i] = 0; rep(i, 0, n) { dp1[i + 1] = max(dp1[i], dp0[i] + j * a[i] + b[i]); } //cout << dp1 << endl; cout << dp1[n] << endl; swap(dp0, dp1); } } |