Submission #995512

# Submission time Handle Problem Language Result Execution time Memory
995512 2024-06-09T08:26:17 Z O_Elmasry Cloud Computing (CEOI18_clo) C++17
100 / 100
324 ms 2264 KB
#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(mxN,-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(int i=0;i<=s;i++)smax(ans,dp[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

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 time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 2 ms 2140 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 2 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1880 KB Output is correct
5 Correct 17 ms 1884 KB Output is correct
6 Correct 3 ms 1884 KB Output is correct
7 Correct 80 ms 2140 KB Output is correct
8 Correct 16 ms 2136 KB Output is correct
9 Correct 131 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1996 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 2136 KB Output is correct
3 Correct 6 ms 1884 KB Output is correct
4 Correct 2 ms 2140 KB Output is correct
5 Correct 156 ms 2140 KB Output is correct
6 Correct 287 ms 2140 KB Output is correct
7 Correct 288 ms 2136 KB Output is correct
8 Correct 279 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2132 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 17 ms 1884 KB Output is correct
4 Correct 4 ms 2140 KB Output is correct
5 Correct 278 ms 2140 KB Output is correct
6 Correct 291 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 2 ms 2140 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 2 ms 2140 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1880 KB Output is correct
13 Correct 17 ms 1884 KB Output is correct
14 Correct 3 ms 1884 KB Output is correct
15 Correct 80 ms 2140 KB Output is correct
16 Correct 16 ms 2136 KB Output is correct
17 Correct 131 ms 2136 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1880 KB Output is correct
20 Correct 2 ms 1884 KB Output is correct
21 Correct 1 ms 1996 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1884 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 1 ms 1884 KB Output is correct
26 Correct 1 ms 1884 KB Output is correct
27 Correct 1 ms 2136 KB Output is correct
28 Correct 6 ms 1884 KB Output is correct
29 Correct 2 ms 2140 KB Output is correct
30 Correct 156 ms 2140 KB Output is correct
31 Correct 287 ms 2140 KB Output is correct
32 Correct 288 ms 2136 KB Output is correct
33 Correct 279 ms 2140 KB Output is correct
34 Correct 1 ms 2132 KB Output is correct
35 Correct 2 ms 2140 KB Output is correct
36 Correct 17 ms 1884 KB Output is correct
37 Correct 4 ms 2140 KB Output is correct
38 Correct 278 ms 2140 KB Output is correct
39 Correct 291 ms 2140 KB Output is correct
40 Correct 21 ms 1884 KB Output is correct
41 Correct 54 ms 2140 KB Output is correct
42 Correct 6 ms 2136 KB Output is correct
43 Correct 318 ms 2140 KB Output is correct
44 Correct 324 ms 2264 KB Output is correct
45 Correct 317 ms 2140 KB Output is correct
46 Correct 3 ms 2140 KB Output is correct
47 Correct 5 ms 2140 KB Output is correct
48 Correct 5 ms 2140 KB Output is correct