Submission #563908

# Submission time Handle Problem Language Result Execution time Memory
563908 2022-05-18T09:14:54 Z tqbfjotld Two Dishes (JOI19_dishes) C++14
15 / 100
183 ms 47628 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n,m;
int A[1000005];
int S[1000005];
int P[1000005];
int B[1000005];
int T[1000005];
int Q[1000005];

int prefA[1000005];
int prefB[1000005];
int prefA2[1000005];
int prefB2[1000005];

int mem[2005][2005];

int dp(int a, int b){
    if (mem[a][b]!=-1) return mem[a][b];
    int ans = -999999999999999999LL;
    if (a==0&&b==0) ans = 0;
    if (a!=0){
        int t = dp(a-1,b);
        if (prefA[a]+prefB[b]<=S[a-1]){
            t += P[a-1];
        }
        ans = max(ans,t);
    }
    if (b!=0){
        int t = dp(a,b-1);
        if (prefA[a]+prefB[b]<=T[b-1]){
            t += Q[b-1];
        }
        ans = max(ans,t);
    }
    return mem[a][b] = ans;
}

 main(){
    scanf("%lld%lld",&n,&m);
    for (int x = 0; x<n; x++){
        scanf("%lld%lld%lld",&A[x],&S[x],&P[x]);
    }
    for (int x = 0; x<m; x++){
        scanf("%lld%lld%lld",&B[x],&T[x],&Q[x]);
    }
    memset(mem,-1,sizeof(mem));
    for (int x = 1; x<=n; x++){
        prefA[x] = prefA[x-1]+A[x-1];
    }
    for (int x = 1; x<=m; x++){
        prefB[x] = prefB[x-1]+B[x-1];
    }
    if (n<=2000&&m<=2000){
        printf("%lld\n",dp(n,m));
        return 0;
    }
    for (int x = 1; x<=n; x++){
        prefA2[x] = prefA2[x-1]+P[x-1];
    }
    for (int x = 1; x<=m; x++){
        prefB2[x] = prefB2[x-1]+Q[x-1];
    }
    int ans = -999999999999999999;
    for (int x = 0; x<=n; x++){
        if (prefA[x]<=S[0]){
            int t = S[0]-prefA[x];
            int t2 = upper_bound(prefB,prefB+m+1,t)-prefB-1;
            ans = max(ans,prefA2[x]+prefB2[t2]);
        }
    }
    printf("%lld",ans);

    /*for (int x = 0; x<=n; x++){
        for (int y = 0; y<=m; y++){
            printf("%4lld ",dp(x,y));
        }
        printf("\n");
    }*/

}

Compilation message

dishes.cpp:41:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 |  main(){
      |  ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
dishes.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%lld%lld%lld",&A[x],&S[x],&P[x]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%lld%lld%lld",&B[x],&T[x],&Q[x]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 156 ms 47568 KB Output is correct
2 Correct 151 ms 47360 KB Output is correct
3 Correct 183 ms 47604 KB Output is correct
4 Correct 157 ms 47352 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 150 ms 46924 KB Output is correct
7 Correct 80 ms 39788 KB Output is correct
8 Correct 82 ms 39744 KB Output is correct
9 Correct 159 ms 47628 KB Output is correct
10 Correct 120 ms 47500 KB Output is correct
11 Correct 133 ms 47512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31792 KB Output is correct
2 Correct 12 ms 31820 KB Output is correct
3 Correct 13 ms 31828 KB Output is correct
4 Correct 15 ms 31776 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 13 ms 31828 KB Output is correct
7 Correct 13 ms 31788 KB Output is correct
8 Correct 14 ms 31724 KB Output is correct
9 Correct 13 ms 31828 KB Output is correct
10 Correct 13 ms 31796 KB Output is correct
11 Correct 14 ms 31816 KB Output is correct
12 Correct 13 ms 31792 KB Output is correct
13 Correct 13 ms 31828 KB Output is correct
14 Correct 13 ms 31796 KB Output is correct
15 Correct 13 ms 31800 KB Output is correct
16 Correct 13 ms 31828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31792 KB Output is correct
2 Correct 12 ms 31820 KB Output is correct
3 Correct 13 ms 31828 KB Output is correct
4 Correct 15 ms 31776 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 13 ms 31828 KB Output is correct
7 Correct 13 ms 31788 KB Output is correct
8 Correct 14 ms 31724 KB Output is correct
9 Correct 13 ms 31828 KB Output is correct
10 Correct 13 ms 31796 KB Output is correct
11 Correct 14 ms 31816 KB Output is correct
12 Correct 13 ms 31792 KB Output is correct
13 Correct 13 ms 31828 KB Output is correct
14 Correct 13 ms 31796 KB Output is correct
15 Correct 13 ms 31800 KB Output is correct
16 Correct 13 ms 31828 KB Output is correct
17 Correct 53 ms 32212 KB Output is correct
18 Correct 43 ms 32176 KB Output is correct
19 Correct 52 ms 32212 KB Output is correct
20 Correct 47 ms 32212 KB Output is correct
21 Correct 45 ms 32212 KB Output is correct
22 Correct 48 ms 32084 KB Output is correct
23 Correct 52 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31792 KB Output is correct
2 Correct 12 ms 31820 KB Output is correct
3 Correct 13 ms 31828 KB Output is correct
4 Correct 15 ms 31776 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 13 ms 31828 KB Output is correct
7 Correct 13 ms 31788 KB Output is correct
8 Correct 14 ms 31724 KB Output is correct
9 Correct 13 ms 31828 KB Output is correct
10 Correct 13 ms 31796 KB Output is correct
11 Correct 14 ms 31816 KB Output is correct
12 Correct 13 ms 31792 KB Output is correct
13 Correct 13 ms 31828 KB Output is correct
14 Correct 13 ms 31796 KB Output is correct
15 Correct 13 ms 31800 KB Output is correct
16 Correct 13 ms 31828 KB Output is correct
17 Correct 53 ms 32212 KB Output is correct
18 Correct 43 ms 32176 KB Output is correct
19 Correct 52 ms 32212 KB Output is correct
20 Correct 47 ms 32212 KB Output is correct
21 Correct 45 ms 32212 KB Output is correct
22 Correct 48 ms 32084 KB Output is correct
23 Correct 52 ms 32084 KB Output is correct
24 Incorrect 131 ms 47584 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31792 KB Output is correct
2 Correct 12 ms 31820 KB Output is correct
3 Correct 13 ms 31828 KB Output is correct
4 Correct 15 ms 31776 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 13 ms 31828 KB Output is correct
7 Correct 13 ms 31788 KB Output is correct
8 Correct 14 ms 31724 KB Output is correct
9 Correct 13 ms 31828 KB Output is correct
10 Correct 13 ms 31796 KB Output is correct
11 Correct 14 ms 31816 KB Output is correct
12 Correct 13 ms 31792 KB Output is correct
13 Correct 13 ms 31828 KB Output is correct
14 Correct 13 ms 31796 KB Output is correct
15 Correct 13 ms 31800 KB Output is correct
16 Correct 13 ms 31828 KB Output is correct
17 Correct 53 ms 32212 KB Output is correct
18 Correct 43 ms 32176 KB Output is correct
19 Correct 52 ms 32212 KB Output is correct
20 Correct 47 ms 32212 KB Output is correct
21 Correct 45 ms 32212 KB Output is correct
22 Correct 48 ms 32084 KB Output is correct
23 Correct 52 ms 32084 KB Output is correct
24 Incorrect 131 ms 47584 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 31792 KB Output is correct
2 Correct 12 ms 31820 KB Output is correct
3 Correct 13 ms 31828 KB Output is correct
4 Correct 15 ms 31776 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 13 ms 31828 KB Output is correct
7 Correct 13 ms 31788 KB Output is correct
8 Correct 14 ms 31724 KB Output is correct
9 Correct 13 ms 31828 KB Output is correct
10 Correct 13 ms 31796 KB Output is correct
11 Correct 14 ms 31816 KB Output is correct
12 Correct 13 ms 31792 KB Output is correct
13 Correct 13 ms 31828 KB Output is correct
14 Correct 13 ms 31796 KB Output is correct
15 Correct 13 ms 31800 KB Output is correct
16 Correct 13 ms 31828 KB Output is correct
17 Correct 53 ms 32212 KB Output is correct
18 Correct 43 ms 32176 KB Output is correct
19 Correct 52 ms 32212 KB Output is correct
20 Correct 47 ms 32212 KB Output is correct
21 Correct 45 ms 32212 KB Output is correct
22 Correct 48 ms 32084 KB Output is correct
23 Correct 52 ms 32084 KB Output is correct
24 Incorrect 131 ms 47584 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 156 ms 47568 KB Output is correct
2 Correct 151 ms 47360 KB Output is correct
3 Correct 183 ms 47604 KB Output is correct
4 Correct 157 ms 47352 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 150 ms 46924 KB Output is correct
7 Correct 80 ms 39788 KB Output is correct
8 Correct 82 ms 39744 KB Output is correct
9 Correct 159 ms 47628 KB Output is correct
10 Correct 120 ms 47500 KB Output is correct
11 Correct 133 ms 47512 KB Output is correct
12 Correct 12 ms 31792 KB Output is correct
13 Correct 12 ms 31820 KB Output is correct
14 Correct 13 ms 31828 KB Output is correct
15 Correct 15 ms 31776 KB Output is correct
16 Correct 12 ms 31796 KB Output is correct
17 Correct 13 ms 31828 KB Output is correct
18 Correct 13 ms 31788 KB Output is correct
19 Correct 14 ms 31724 KB Output is correct
20 Correct 13 ms 31828 KB Output is correct
21 Correct 13 ms 31796 KB Output is correct
22 Correct 14 ms 31816 KB Output is correct
23 Correct 13 ms 31792 KB Output is correct
24 Correct 13 ms 31828 KB Output is correct
25 Correct 13 ms 31796 KB Output is correct
26 Correct 13 ms 31800 KB Output is correct
27 Correct 13 ms 31828 KB Output is correct
28 Correct 53 ms 32212 KB Output is correct
29 Correct 43 ms 32176 KB Output is correct
30 Correct 52 ms 32212 KB Output is correct
31 Correct 47 ms 32212 KB Output is correct
32 Correct 45 ms 32212 KB Output is correct
33 Correct 48 ms 32084 KB Output is correct
34 Correct 52 ms 32084 KB Output is correct
35 Incorrect 131 ms 47584 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 156 ms 47568 KB Output is correct
2 Correct 151 ms 47360 KB Output is correct
3 Correct 183 ms 47604 KB Output is correct
4 Correct 157 ms 47352 KB Output is correct
5 Correct 12 ms 31796 KB Output is correct
6 Correct 150 ms 46924 KB Output is correct
7 Correct 80 ms 39788 KB Output is correct
8 Correct 82 ms 39744 KB Output is correct
9 Correct 159 ms 47628 KB Output is correct
10 Correct 120 ms 47500 KB Output is correct
11 Correct 133 ms 47512 KB Output is correct
12 Correct 12 ms 31792 KB Output is correct
13 Correct 12 ms 31820 KB Output is correct
14 Correct 13 ms 31828 KB Output is correct
15 Correct 15 ms 31776 KB Output is correct
16 Correct 12 ms 31796 KB Output is correct
17 Correct 13 ms 31828 KB Output is correct
18 Correct 13 ms 31788 KB Output is correct
19 Correct 14 ms 31724 KB Output is correct
20 Correct 13 ms 31828 KB Output is correct
21 Correct 13 ms 31796 KB Output is correct
22 Correct 14 ms 31816 KB Output is correct
23 Correct 13 ms 31792 KB Output is correct
24 Correct 13 ms 31828 KB Output is correct
25 Correct 13 ms 31796 KB Output is correct
26 Correct 13 ms 31800 KB Output is correct
27 Correct 13 ms 31828 KB Output is correct
28 Correct 53 ms 32212 KB Output is correct
29 Correct 43 ms 32176 KB Output is correct
30 Correct 52 ms 32212 KB Output is correct
31 Correct 47 ms 32212 KB Output is correct
32 Correct 45 ms 32212 KB Output is correct
33 Correct 48 ms 32084 KB Output is correct
34 Correct 52 ms 32084 KB Output is correct
35 Incorrect 131 ms 47584 KB Output isn't correct
36 Halted 0 ms 0 KB -