Submission #400291

#TimeUsernameProblemLanguageResultExecution timeMemory
400291SavicSCloud Computing (CEOI18_clo)C++14
0 / 100
11 ms3448 KiB
#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[4] > s2[4]; return s1[1] > s2[1]; } const int N = 200000; 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); memset(dp, -inf, sizeof(dp)); 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 = -inf; 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 (stderr)

clo.cpp: In function 'int main()':
clo.cpp:57:16: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow]
   57 |     memset(dp, -inf, sizeof(dp));
      |                ^~~~
clo.cpp:61:13: warning: unused variable 'B' [-Wunused-variable]
   61 |         int B = vec[i][1];
      |             ^
#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...