Submission #152590

#TimeUsernameProblemLanguageResultExecution timeMemory
152590MercenaryCloud Computing (CEOI18_clo)C++14
100 / 100
396 ms1400 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e3 + 5;

ll dp[maxn * 50];

struct object{
    int c , f , v;
    bool operator < (const object & other){
        if(f == other.f)return v < other.v;
        return f > other.f;
    }
}a[maxn * 2];

int n , m;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].c >> a[i].f >> a[i].v;
        a[i].v = -a[i].v;
    }
    cin >> m;
    for(int i = 1 ; i <= m ; ++i){
        cin >> a[i + n].c >> a[i + n].f >> a[i + n].v;
    }
    sort(a + 1 , a + n + m + 1);
    fill_n(&dp[0],maxn*50,-1e18);
    dp[0] = 0;
    for(int i = 1 ; i <= n + m ; ++i){
        if(a[i].v < 0){
            for(int j = 100000 - a[i].c ; j >= 0 ; --j){
                dp[j + a[i].c] = max(dp[j + a[i].c] , dp[j] + a[i].v);
            }
        }else{
            for(int j = a[i].c ; j <= 100000 ; ++j){
                dp[j - a[i].c] = max(dp[j - a[i].c] , dp[j] + a[i].v);
            }
        }
    }
    cout << *max_element(dp,dp+maxn*50);
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:37:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:38:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".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...