Submission #400294

# Submission time Handle Problem Language Result Execution time Memory
400294 2021-05-07T19:44:40 Z SavicS Cloud Computing (CEOI18_clo) C++14
100 / 100
713 ms 2088 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2005;
const ll inf = 1e18 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, m;

vector<array<int,4>> vec;
bool cmp(array<int,4> s1, array<int,4> s2){
    if(s1[1] == s2[1])return s1[3] > s2[3];
    return s1[1] > s2[1];
}

const int N = 100000;
ll dp[2][N + 5];

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n;
    ff(i,1,n){
        int A, B, C;
        cin >> A >> B >> C;
        vec.pb({A, B, C, 1});
    }
    cin >> m;
    ff(i,1,m){
        int A, B, C;
        cin >> A >> B >> C;
        vec.pb({A, B, C, 0});
    }
    sort(all(vec), cmp);

    ff(i,0,N)dp[0][i] = dp[1][i] = -inf;

    dp[0][0] = 0;
    ff(i,0,sz(vec) - 1){
        int A = vec[i][0];
        int B = vec[i][1];
        int C = vec[i][2];
        int T = vec[i][3];

        int cur = (i + 1) % 2;
        int pre = i % 2;

        if(T == 1){
            ff(j,0,N){
                dp[cur][j] = dp[pre][j];
                // ako uzimam i-ti objekat
                if(j >= A)dp[cur][j] = max(dp[cur][j], dp[pre][j - A] - C);
            }
        }
        else{
            ff(j,0,N){
                dp[cur][j] = dp[pre][j];
                if(j + A <= N)dp[cur][j] = max(dp[cur][j], dp[pre][j + A] + C);
            }
        }

    }

    ll rez = 0;
    ff(j,0,N)rez = max(rez, dp[(n + m) % 2][j]);
    cout << rez << endl;

    return 0;
}
/**

4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550


// probati bojenje sahovski ili slicno

**/

Compilation message

clo.cpp: In function 'int main()':
clo.cpp:62:13: warning: unused variable 'B' [-Wunused-variable]
   62 |         int B = vec[i][1];
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 19 ms 1868 KB Output is correct
4 Correct 34 ms 1868 KB Output is correct
5 Correct 309 ms 1924 KB Output is correct
6 Correct 300 ms 1868 KB Output is correct
7 Correct 322 ms 1940 KB Output is correct
8 Correct 319 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 3 ms 1868 KB Output is correct
3 Correct 19 ms 1868 KB Output is correct
4 Correct 19 ms 1868 KB Output is correct
5 Correct 151 ms 1896 KB Output is correct
6 Correct 149 ms 1896 KB Output is correct
7 Correct 325 ms 1924 KB Output is correct
8 Correct 329 ms 1944 KB Output is correct
9 Correct 316 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1880 KB Output is correct
2 Correct 6 ms 1868 KB Output is correct
3 Correct 33 ms 1868 KB Output is correct
4 Correct 30 ms 1868 KB Output is correct
5 Correct 59 ms 1876 KB Output is correct
6 Correct 61 ms 1868 KB Output is correct
7 Correct 83 ms 1884 KB Output is correct
8 Correct 97 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1868 KB Output is correct
2 Correct 4 ms 1868 KB Output is correct
3 Correct 251 ms 1928 KB Output is correct
4 Correct 302 ms 1868 KB Output is correct
5 Correct 632 ms 1996 KB Output is correct
6 Correct 712 ms 2032 KB Output is correct
7 Correct 661 ms 2036 KB Output is correct
8 Correct 628 ms 2032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1868 KB Output is correct
2 Correct 30 ms 1888 KB Output is correct
3 Correct 131 ms 1868 KB Output is correct
4 Correct 323 ms 1928 KB Output is correct
5 Correct 667 ms 1996 KB Output is correct
6 Correct 655 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 19 ms 1868 KB Output is correct
4 Correct 34 ms 1868 KB Output is correct
5 Correct 309 ms 1924 KB Output is correct
6 Correct 300 ms 1868 KB Output is correct
7 Correct 322 ms 1940 KB Output is correct
8 Correct 319 ms 1868 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 3 ms 1868 KB Output is correct
11 Correct 19 ms 1868 KB Output is correct
12 Correct 19 ms 1868 KB Output is correct
13 Correct 151 ms 1896 KB Output is correct
14 Correct 149 ms 1896 KB Output is correct
15 Correct 325 ms 1924 KB Output is correct
16 Correct 329 ms 1944 KB Output is correct
17 Correct 316 ms 1868 KB Output is correct
18 Correct 6 ms 1880 KB Output is correct
19 Correct 6 ms 1868 KB Output is correct
20 Correct 33 ms 1868 KB Output is correct
21 Correct 30 ms 1868 KB Output is correct
22 Correct 59 ms 1876 KB Output is correct
23 Correct 61 ms 1868 KB Output is correct
24 Correct 83 ms 1884 KB Output is correct
25 Correct 97 ms 1876 KB Output is correct
26 Correct 4 ms 1868 KB Output is correct
27 Correct 4 ms 1868 KB Output is correct
28 Correct 251 ms 1928 KB Output is correct
29 Correct 302 ms 1868 KB Output is correct
30 Correct 632 ms 1996 KB Output is correct
31 Correct 712 ms 2032 KB Output is correct
32 Correct 661 ms 2036 KB Output is correct
33 Correct 628 ms 2032 KB Output is correct
34 Correct 4 ms 1868 KB Output is correct
35 Correct 30 ms 1888 KB Output is correct
36 Correct 131 ms 1868 KB Output is correct
37 Correct 323 ms 1928 KB Output is correct
38 Correct 667 ms 1996 KB Output is correct
39 Correct 655 ms 1996 KB Output is correct
40 Correct 173 ms 1912 KB Output is correct
41 Correct 330 ms 1948 KB Output is correct
42 Correct 486 ms 2024 KB Output is correct
43 Correct 670 ms 2048 KB Output is correct
44 Correct 638 ms 2052 KB Output is correct
45 Correct 713 ms 2088 KB Output is correct
46 Correct 381 ms 1952 KB Output is correct
47 Correct 508 ms 2024 KB Output is correct
48 Correct 519 ms 2024 KB Output is correct