제출 #481290

#제출 시각아이디문제언어결과실행 시간메모리
481290BackNoobCloud Computing (CEOI18_clo)C++14
0 / 100
10 ms1884 KiB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define mask(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
using namespace std;
const int mxN = 4e3 + 227;
const ll inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

struct item{
	int cores , f , cost;
	bool operator<(const item &a) const {
		if(f == a.f) return cost < a.cost;
		return f > a.f;
	}
} a[mxN];

ll dp[200007];
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("task.inp" , "r" , stdin);
    //freopen("task.out" , "w" , stdout);
    
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) {
    	int x , y , z;
    	cin >> x >> y >> z;
    	x = x;
    	z = -z;
    	a[i] = {x , y , z};
    }

    int m;
    cin >> m;
    for(int i = n + 1 ; i <= n + m ; i++) {
    	int x , y , z;
    	cin >> x >> y >> z;
    	x = -x;
    	a[i] = {x , y , z};
    }

    sort(a + 1 , a + 1 + n + m );

    memset(dp , -0x3f , sizeof(dp));
    dp[0] = 0;

    for(int i = 1 ; i <= n + m ; i++) {
    	cout << a[i].cores << ' ' << a[i].f << ' ' << a[i].cost << endl;
    	if(a[i].cores >= 0) {
	    	for(int j = 200000 ; j >= 0 ; j--) {
	    		if(j - a[i].cores >= 0) {
	    			maximize(dp[j] , dp[j - a[i].cores] + a[i].cost);
	    		}
	    	}
	    }
	    else {
	    	for(int j = 0 ; j <= 200000 + a[i].cores ; j++) {
	    		maximize(dp[j] , dp[j - a[i].cores] + a[i].cost);
	    	}
	    }
    }


    ll res = 0;
    for(int i = 0 ; i <= 200000 ; i++) maximize(res , dp[i]);

    cout << res;
    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...