제출 #361770

#제출 시각아이디문제언어결과실행 시간메모리
361770arujbansalCloud Computing (CEOI18_clo)C++17
100 / 100
446 ms1388 KiB
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define all(x) (x).begin(), (x).end() #define sz(x) (int) (x).size() #define int long long const int MXN = 1e5 + 5, INF = 1e18; struct Computer { int cores, freq, price; Computer(int cores, int freq, int price) : cores(cores), freq(freq), price(price) {} bool operator<(const Computer &other) const { if (freq == other.freq) { return price < other.price; } return freq > other.freq; } }; void solve() { int N; cin >> N; vector<Computer> computers; for (int i = 0; i < N; i++) { int cores, freq, price; cin >> cores >> freq >> price; computers.emplace_back(cores, freq, -price); } int M; cin >> M; for (int i = 0; i < M; i++) { int cores, freq, price; cin >> cores >> freq >> price; computers.emplace_back(cores, freq, price); } sort(all(computers)); vector<int> dp(MXN, -INF); dp[0] = 0; for (int i = 0; i < sz(computers); i++) { if (computers[i].price < 0) { // This is a computer we have for (int j = MXN - 1; j >= computers[i].cores; j--) { dp[j] = max(dp[j], dp[j - computers[i].cores] + computers[i].price); } } else { // This is an order for (int j = 0; j < MXN; j++) { if (j + + computers[i].cores < MXN) { dp[j] = max(dp[j], dp[j + computers[i].cores] + computers[i].price); } } } } cout << *max_element(all(dp)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef local freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int TC = 1; // cin >> TC; while (TC--) solve(); }
#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...