This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define arr(x) array<ll , x>
#define endl '\n'
#define cl clear
#define bg begin
int n , m , sum;
vector<int> ord;
vector<arr(3)> a;
ll dp[4000][10000] , o;
ll f(int i , int j){
if(dp[i][j] != -1) return dp[i][j];
if(i >= n + m or j >= sum) return 0;
dp[i][j] = f(i + 1 , j);
dp[i][j] = max(dp[i][j] , f(i , j + 1));
if(j + a[i][0] <= sum and ord[j] >= a[i][1]){
dp[i][j] = max(dp[i][j] , a[i][2] + f(i + 1 , j + a[i][0]));
}
return dp[i][j];
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0 ; i < n ; i++){
int c , f , v;
cin >> c >> f >> v;
a.pb({c , f , v}) , o -= (1ll * v) , sum += c;
for(int i = 0 ; i < c ; i++) ord.pb(f);
}
cin >> m;
for(int i = 0 ; i < m ; i++){
int c , f , v;
cin >> c >> f >> v;
a.pb({c , f , v});
}
fill(&dp[0][0] , &dp[3999][10000] , -1);
sort(a.bg() , a.end() , [](arr(3) a , arr(3) b){
return (a[1] < b[1]);
});
sort(ord.bg() , ord.end());
exit(0);
cout << f(0 , 0) + o;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |