Submission #995509

#TimeUsernameProblemLanguageResultExecution timeMemory
995509O_ElmasryCloud Computing (CEOI18_clo)C++17
0 / 100
256 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define yes cout << "YES" << endl #define no cout << "NO" << endl #define ll long long #define int long long #define pb push_back #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define mem(v, x) memset(v, x, sizeof v); #ifndef ONLINE_JUDGE #define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl; #else #define dbg(v) #endif template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream &operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } const ll mxN = (int)2e5 + 5, mod = 998244353 /*1e9+7*/, INF = 1e18; void file(string name) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * ((uint64_t) new char | 1)); template <typename T> T Rand(T low, T high) { return uniform_int_distribution<T>(low, high)(rng); } template <typename T> inline void smin(T &a, T b) { a = min(a, b); } template <typename T> inline void smax(T &a, T b) { a = max(a, b); } struct computer{ int c,f,v; friend istream &operator>>(istream &is,computer &p){ is >> p.c >> p.f >> p.v; return is; } friend ostream &operator<<(ostream &os,computer &p){ os << p.c << " " << p.f << " " << p.v; return os; } bool operator<(const computer &p){ if(p.f==f)return c>p.c; return f>p.f; } }; void solve() { vector<computer>v; int n; cin >> n; int s=0; for(int i=0;i<n;i++){ computer cur; cin >> cur; s+=cur.c; cur.v*=-1; v.pb(cur); } int m; cin >> m; for(int i=0;i<m;i++){ computer cur; cin >> cur; cur.c*=-1; v.pb(cur); } sort(all(v)); vector<int>dp(s+1,-INF); dp[0]=0; for(int i=0;i<v.size();i++){ if(v[i].c<0){ for(int j=0;j<=s+v[i].c;j++){ smax(dp[j],dp[j-v[i].c]+v[i].v); } } else{ for(int j=s;j>=v[i].c;j--){ smax(dp[j],dp[j-v[i].c]+v[i].v); } } } ll ans=0; // for(auto &i:dp)cout << i << endl; for(auto &i:dp)smax(ans,i); cout << ans << endl; } signed main() { ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE file("test"); #endif int tc = 1; // cin >> tc; while (tc--) { solve(); } }

Compilation message (stderr)

clo.cpp: In function 'void solve()':
clo.cpp:83:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<computer>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for(int i=0;i<v.size();i++){
      |                     ~^~~~~~~~~
clo.cpp: In function 'void file(std::string)':
clo.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen((name + ".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...