Submission #1033287

#TimeUsernameProblemLanguageResultExecution timeMemory
1033287nmtsCloud Computing (CEOI18_clo)C++17
100 / 100
687 ms2304 KiB
#include <bits/stdc++.h> #define file(name) freopen(name".inp" , "r" , stdin);freopen(name".out" , "w" , stdout) #define quick ios_base :: sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; #define pii pair < int , int > #define ll long long #define vi vector<int> #define fi first #define se second #define FOR(i,l,r) for (int i=l;i<=r;i++) #define endl '\n' #define MASK(i) (1LL << (i)) #define c_bit(i) __builtin_popcountll(i) // đếm số bit đang bật #define r_bit(i) __builtin_ctz(i) #define BIT(x, i) (x>>i) & 1 // trạng thái của bit thứ i trong x #define SET_ON(x, i) ((x) | MASK(i)) // bật bit thứ i trong x #define SET_OFF(x, i) ((x) & ~MASK(i)) // tắt bit thứ i trong x const int N = 1e5 + 6 ; const int INF=1e9; using namespace std; struct tt { int T; long long c,f,v; }; bool cmp (tt a, tt b) { if (a.f!=b.f) return a.f<b.f; return a.T>b.T; } int n,m; long long d[N],dp[N]; vector <tt> a; int main() { quick; //file("cloud"); cin>>n; for (int i=1;i<=n;i++) { int c,f,v; cin>>c>>f>>v; a.push_back({0,c,f,v}); } cin>>m; for (int i=1;i<=m;i++) { int c,f,v; cin>>c>>f>>v; a.push_back({1,c,f,v}); } sort(a.begin(),a.end(),cmp); for (int i=0;i<n+m;i++) { for (int j=0;j<=m*50;j++) { dp[j]=max(dp[j],d[j]); if (a[i].T==1) { if (j>=a[i].c) dp[j]=max(dp[j],d[j-a[i].c]+a[i].v); } else { if (j+a[i].c<=m*50) dp[j]=max(dp[j],d[j+a[i].c]-a[i].v); } } for (int j=0;j<=m*50;j++) d[j]=dp[j]; } cout<<dp[0]; 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...