Submission #523533

#TimeUsernameProblemLanguageResultExecution timeMemory
523533LoboCloud Computing (CEOI18_clo)C++17
100 / 100
518 ms2084 KiB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 4020

int n, m, dp[2][25*maxn];
pair<pair<int,int>,pair<int,int>> a[maxn];


void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int c,f,v;
        cin >> c >> f >> v;
        a[i].fr.fr = f;
        a[i].fr.sc = 1; //comprar vem depois de vender
        a[i].sc.fr = c;
        a[i].sc.sc = v;
    }

    cin >> m;

    for(int i = 1; i <= m; i++) {
        int c,f,v;
        cin >> c >> f >> v;
        a[i+n].fr.fr = f;
        a[i+n].fr.sc = 0; //comprar vem depois de vender
        a[i+n].sc.fr = c;
        a[i+n].sc.sc = v;
    }

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

    for(int i = 1; i <= n+m; i++) {
        int c,v,tp;
        c = a[i].sc.fr;
        v = a[i].sc.sc;
        tp = a[i].fr.sc;

        // cout << c << " " << v << " " << tp << endl;
        for(int qtd = 0; qtd <= 50*n; qtd++) {
            if(tp == 0) {
                //venda
                //nao usa
                dp[i&1][qtd] = dp[i&1^1][qtd];
                
                //usa
                if(qtd-c >= 0) {
                    dp[i&1][qtd] = max(dp[i&1][qtd], dp[i&1^1][qtd-c] + v);
                }
            }
            else {
                //compra
                //nao usa
                dp[i&1][qtd] = dp[i&1^1][qtd];

                //usa
                dp[i&1][qtd] = max(dp[i&1][qtd],dp[i&1^1][qtd+c] - v);
            }
        }
    }

    cout << dp[(n+m)&1][0] << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
    
    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}

Compilation message (stderr)

clo.cpp: In function 'void solve()':
clo.cpp:56:36: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   56 |                 dp[i&1][qtd] = dp[i&1^1][qtd];
      |                                   ~^~
clo.cpp:60:58: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   60 |                     dp[i&1][qtd] = max(dp[i&1][qtd], dp[i&1^1][qtd-c] + v);
      |                                                         ~^~
clo.cpp:66:36: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   66 |                 dp[i&1][qtd] = dp[i&1^1][qtd];
      |                                   ~^~
clo.cpp:69:53: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   69 |                 dp[i&1][qtd] = max(dp[i&1][qtd],dp[i&1^1][qtd+c] - v);
      |                                                    ~^~
#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...