Submission #1106029

# Submission time Handle Problem Language Result Execution time Memory
1106029 2024-10-29T02:24:58 Z whoknow Cloud Computing (CEOI18_clo) C++17
100 / 100
956 ms 2244 KB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MAXN 2005
#define MAXCORE 100005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
const ll INF = 1e18;
int n, m;
struct arr
{
    int c, f, w;
};
arr a[MAXN], b[MAXN];
namespace sub1
{
int maxc;
ll res;
ll dp[2][MAXCORE];
vector<arr>v;
bool cmp(arr x, arr y)
{
    if(x.f == y.f)
        return x.c > y.c;
    return x.f > y.f;
}
void solve()
{
    for(int i=1;i<=n;i++)
        maxc+=a[i].c;
    for(int i = 1; i <= n; i++)
        v.push_back({a[i].c, a[i].f, -a[i].w});
    for(int i = 1; i <= m; i++)
        v.push_back({-b[i].c, b[i].f, b[i].w});
    sort(v.begin(), v.end(), cmp);
    for(int i=0;i<=1;i++)
        for(int j=0;j<=maxc;j++)
            dp[i][j]=-INF;
    dp[0][0]=0;
    for(int i=0;i<sz(v);i++)
    {
        if(v[i].c>=0)
            dp[1][v[i].c]=v[i].w;
        for(int j=maxc;j>=0;j--)
        {
            int k=j+v[i].c;
            dp[1][j]=max(dp[1][j],dp[0][j]);
            if(k>=0&&k<=maxc&&dp[0][j]<=1e14)
                dp[1][k]=max(dp[1][k],dp[0][j]+v[i].w);
//            cout<<v[i].c<<" "<<v[i].f<<" "<<v[i].w<<" "<<j<<" "<<dp[1][j]<<endl;
        }
        for(int j=0;j<=maxc;j++)
        {
            dp[0][j]=dp[1][j];
            dp[1][j]=-INF;
        }
    }
    for(int k=0;k<=maxc;k++)
        res=max(res,dp[0][k]);
    cout << res;
}
}
main()
{
    if(fopen("TEST.inp", "r"))
    {
        freopen("TESt.inp", "r", stdin);
        freopen("TESt.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i].c >> a[i].f >> a[i].w;
    cin >> m;
    for(int i = 1; i <= m; i++)
        cin >> b[i].c >> b[i].f >> b[i].w;
    sub1::solve();
}
/**

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

Compilation message

clo.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
clo.cpp: In function 'int main()':
clo.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("TESt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen("TESt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 51 ms 848 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 234 ms 1360 KB Output is correct
8 Correct 54 ms 592 KB Output is correct
9 Correct 402 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 16 ms 632 KB Output is correct
4 Correct 3 ms 336 KB Output is correct
5 Correct 460 ms 1360 KB Output is correct
6 Correct 864 ms 2052 KB Output is correct
7 Correct 861 ms 2128 KB Output is correct
8 Correct 779 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 48 ms 908 KB Output is correct
4 Correct 10 ms 612 KB Output is correct
5 Correct 797 ms 1872 KB Output is correct
6 Correct 893 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 4 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 51 ms 848 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 234 ms 1360 KB Output is correct
16 Correct 54 ms 592 KB Output is correct
17 Correct 402 ms 1872 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 16 ms 632 KB Output is correct
29 Correct 3 ms 336 KB Output is correct
30 Correct 460 ms 1360 KB Output is correct
31 Correct 864 ms 2052 KB Output is correct
32 Correct 861 ms 2128 KB Output is correct
33 Correct 779 ms 1872 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 48 ms 908 KB Output is correct
37 Correct 10 ms 612 KB Output is correct
38 Correct 797 ms 1872 KB Output is correct
39 Correct 893 ms 1872 KB Output is correct
40 Correct 52 ms 848 KB Output is correct
41 Correct 146 ms 1104 KB Output is correct
42 Correct 12 ms 592 KB Output is correct
43 Correct 942 ms 2212 KB Output is correct
44 Correct 939 ms 2128 KB Output is correct
45 Correct 956 ms 2244 KB Output is correct
46 Correct 6 ms 592 KB Output is correct
47 Correct 11 ms 592 KB Output is correct
48 Correct 12 ms 592 KB Output is correct