제출 #1006407

#제출 시각아이디문제언어결과실행 시간메모리
1006407makanhuliaCloud Computing (CEOI18_clo)C++17
54 / 100
270 ms1372 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define lld double #define int ll #define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout); template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } // const ll INF = 1e18; const int INF = 1e18; const int mod = 1e9+7; const lld PI = acos(-1.0); int di[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dj[] = {0, 0, 1, -1, 1, -1, 1, -1}; #define debug(x) cout << #x << ": " << x << endl; #define add(a, b) a += b, a %= mod #define mul(a, b) ((a % mod) * (b % mod)) % mod #define all(x) x.begin(),x.end() const int N = 1e5+69; #define info tuple<int, int, int, int> void solve() { int n;cin>>n; vector<info> a; for (int i = 0; i < n; i++) { int c,f,v;cin>>c>>f>>v; // value, freq, cost a.push_back({f,c, v,0}); } int m;cin>>m; for (int i = 0; i < m; i++) { int c,f,v;cin>>c>>f>>v; a.push_back({f, c, v, 1}); } vector<int> dp(N, -INF); dp[0] = 0; sort(all(a)); reverse(all(a)); // cout << dp << endl; // for (auto [x, y, z, k] : a) cout << x << " " << y << " " << z << " " << k << endl; for (int i = 0; i < n+m; i++) { auto [x, y, z, k] = a[i]; if (k == 0) { // buy for (int j = N-1; j >= 0; j--) { if (j-y >= 0) dp[j] = max(dp[j], dp[j - y] - z); } } else { // sell for (int j = 0; j < N; j++) { if (j+y < N)dp[j] = max(dp[j], dp[j + y] + z); } } } // cout << dp << endl; cout << *max_element(all(dp)) << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0); int t=1; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...