Submission #521478

#TimeUsernameProblemLanguageResultExecution timeMemory
5214781ns3rtN4m3H3r3Cloud Computing (CEOI18_clo)C++17
100 / 100
681 ms2224 KiB
#include <bits/stdc++.h>
#if __has_include("debug.h")
    #include "debug.h"
#endif

using namespace std;

template<typename... T>
void read(T&... args) { ((cin >> args), ...);}
template<typename... T>
void out(T&&... args) { ((cout << args << " "), ...);}
template<typename... T>
void outl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
#define int long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define clr(x) memset(x, 0, sizeof(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i+=1)
#define foe(v, l) for (auto v: l)
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define sz(x) int((x).size())
#define PI 3.1415926535897932384626433832795
#define reada(a,x,y) for(int i=x;i<y;i++){cin>>a[i];}
#define readv(v,n) for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);}
#define reads(s,n) for(int i=0;i<n;i++){int x; cin>>x; s.insert(x);}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;

// #warning reset variables after debugging
const int MOD = 1e9+7;
const ll INF = 1e18;
const int MX = 1e9;

void setIO(string fileName = "") {
	if((int)fileName.size()) {
		freopen((fileName+".in").c_str(), "r", stdin);
		freopen((fileName+".out").c_str(), "w", stdout);
	}
}

struct T {
    int c;
    int r;
    int p;
};

void solve(){
    vector<T> pos_t;
    int mx_comp = 0;
    int n; read(n);
    fo(i, n){
        T trans;
        read(trans.c, trans.r, trans.p);
        trans.p *= -1;
        pos_t.pb(trans);
        mx_comp += trans.c;
    }
    int m; read(m);
    fo(i, m){
        T trans;
        read(trans.c, trans.r, trans.p);
        trans.c *= -1;
        pos_t.pb(trans);
    }
    sort(pos_t.begin(), pos_t.end(), [](T a, T b){return a.r!=b.r ? a.r>b.r: a.p<b.p;});
    vi dp(mx_comp+1, -INF);
    dp[0] = 0;
    for(T t: pos_t){
        vi new_max(dp);
		for (int c = 0; c <= mx_comp; c++) {
			int prev_comp = c - t.c;
			if (0 <= prev_comp && prev_comp <= mx_comp
					&& dp[prev_comp] != INT64_MIN) {
				new_max[c] = max(new_max[c], dp[prev_comp] + t.p);
			}
		}
		dp = new_max;
    }
    cout<<*max_element(dp.begin(), dp.end())<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // setIO("");
    int t = 1;
    // cin >> t;
    while(t--) solve();
}

Compilation message (stderr)

clo.cpp: In function 'void setIO(std::string)':
clo.cpp:52:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   freopen((fileName+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:53:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   freopen((fileName+".out").c_str(), "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...