Submission #860766

# Submission time Handle Problem Language Result Execution time Memory
860766 2023-10-14T07:51:33 Z browntoad Two Dishes (JOI19_dishes) C++14
10 / 100
113 ms 31840 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define SZ(x) (int)((x).size())

const ll maxn = 2005;
const ll inf = (1ll<<60);
const ll mod = 1e9+7;

int n, m;
int dp[maxn][maxn];
signed main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin>>n>>m;
	vector<int> a(n+1), s(n+1), p(n+1);
	vector<int> b(m+1), t(m+1), q(m+1);
	REP1(i, n) cin>>a[i]>>s[i]>>p[i];
	REP1(j, m) cin>>b[j]>>t[j]>>q[j];
	REP1(i, n) a[i] += a[i-1];
	REP1(j, m) b[j] += b[j-1];

	if (n > 2000 || m > 2000){
		REP1(i, n) p[i] += p[i-1];
		REP1(j, m) q[j] += q[j-1];
		int k = s[1];
		int mx = -inf;
		int tot = 0;
		REP(i, n+1){
			if (a[i] <= k) tot = p[i];			
			int id = upper_bound(ALL(b), k-a[i]) - b.begin();
			id = max(0ll, id-1);
			mx = max(mx, q[id] + tot);
		}
		cout<<mx<<endl;
		return 0;
	}

	REP(i, n+1){
		REP(j, m+1){
			if (i > 0) dp[i][j] = max(dp[i][j], dp[i-1][j] + (a[i]+b[j] <= s[i]));
			if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j-1] + (a[i]+b[j] <= t[j]));
		}
	}
	cout<<dp[n][m]<<endl;


}
# Verdict Execution time Memory Grader output
1 Correct 106 ms 9816 KB Output is correct
2 Correct 113 ms 23248 KB Output is correct
3 Correct 107 ms 23124 KB Output is correct
4 Correct 112 ms 23388 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 27 ms 31840 KB Output is correct
18 Correct 27 ms 31828 KB Output is correct
19 Correct 27 ms 31832 KB Output is correct
20 Correct 26 ms 31764 KB Output is correct
21 Correct 25 ms 30556 KB Output is correct
22 Correct 26 ms 31832 KB Output is correct
23 Correct 26 ms 31836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 27 ms 31840 KB Output is correct
18 Correct 27 ms 31828 KB Output is correct
19 Correct 27 ms 31832 KB Output is correct
20 Correct 26 ms 31764 KB Output is correct
21 Correct 25 ms 30556 KB Output is correct
22 Correct 26 ms 31832 KB Output is correct
23 Correct 26 ms 31836 KB Output is correct
24 Incorrect 94 ms 9820 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 27 ms 31840 KB Output is correct
18 Correct 27 ms 31828 KB Output is correct
19 Correct 27 ms 31832 KB Output is correct
20 Correct 26 ms 31764 KB Output is correct
21 Correct 25 ms 30556 KB Output is correct
22 Correct 26 ms 31832 KB Output is correct
23 Correct 26 ms 31836 KB Output is correct
24 Incorrect 94 ms 9820 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 396 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 27 ms 31840 KB Output is correct
18 Correct 27 ms 31828 KB Output is correct
19 Correct 27 ms 31832 KB Output is correct
20 Correct 26 ms 31764 KB Output is correct
21 Correct 25 ms 30556 KB Output is correct
22 Correct 26 ms 31832 KB Output is correct
23 Correct 26 ms 31836 KB Output is correct
24 Incorrect 94 ms 9820 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 9816 KB Output is correct
2 Correct 113 ms 23248 KB Output is correct
3 Correct 107 ms 23124 KB Output is correct
4 Correct 112 ms 23388 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 9816 KB Output is correct
2 Correct 113 ms 23248 KB Output is correct
3 Correct 107 ms 23124 KB Output is correct
4 Correct 112 ms 23388 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -