Submission #1029923

#TimeUsernameProblemLanguageResultExecution timeMemory
1029923Peter2017Cloud Computing (CEOI18_clo)C++14
100 / 100
1839 ms3932 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define pill pair<int,ll> #define mem(a, b) memset(a, b, sizeof(a)) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define name "test" using namespace std; const int N = 2e3 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;} template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;} struct item{ int c, f, v; bool operator<(const item &other) const { return f > other.f; } }; int n; int m; item a[N]; item b[N]; ll f[2][N][105]; void load(){ cin.tie(0)->sync_with_stdio(0); if (fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } } void input(){ cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].c >> a[i].f >> a[i].v; cin >> m; for (int i = 1; i <= m; i++) cin >> b[i].c >> b[i].f >> b[i].v; } void solve(){ sort(a + 1, a + n + 1); sort(b + 1, b + m + 1); mem(f, -0x3f); f[0][0][0] = 0; for (int i = 1; i <= n; i++){ int cur = i & 1; int pre = cur ^ 1; f[cur][0][0] = 0; for (int k = 100; k >= 0; k--){ maxi(f[cur][0][k], f[pre][0][k]); maxi(f[cur][0][k], f[cur][0][k + 1]); if (k >= a[i].c) maxi(f[cur][0][k], f[pre][0][k - a[i].c] - a[i].v); } for (int j = 1; j <= m; j++){ for (int k = 100; k >= 0; k--){ maxi(f[cur][j][k], f[pre][j][k]); maxi(f[cur][j][k], f[cur][j - 1][k]); maxi(f[cur][j][k], f[cur][j][k + 1]); if (k >= a[i].c) maxi(f[cur][j][k], f[pre][j][k - a[i].c] - a[i].v); if (b[j].f <= a[i].f && k >= b[j].c) maxi(f[cur][j][k - b[j].c], f[cur][j - 1][k] + b[j].v); } } mem(f[pre], -0x3f); } cout << f[n & 1][m][0]; } int main(){ load(); input(); solve(); }

Compilation message (stderr)

clo.cpp: In function 'void load()':
clo.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...