Submission #259181

# Submission time Handle Problem Language Result Execution time Memory
259181 2020-08-07T10:32:12 Z patrikpavic2 Two Dishes (JOI19_dishes) C++17
3 / 100
393 ms 53156 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
 
#define X first 
#define Y second
#define PB push_back
 
using namespace std;
 
 
typedef long long ll;
typedef pair < int, ll > pii;
 
const int N = 1e6 + 50;
const ll INF = 1e18;
 
ll del[N],  mora[N], S[N], T[N];
int n, m;
int Q[N], P[N], A[N], B[N];
int SS[N], TT[N];
vector < ll > v, v2;
vector < int > brisi[N];
set < pii > ostalo;
 
/** 
 
int bio[N][N];
ll dp[N][N];
 
ll f(int x, int y){
	if(x == 0 && y == 0) return 0;
	if(bio[x][y]) return dp[x][y];
	ll ret = -INF;
	if(x)
		ret = max(ret, f(x - 1, y) + (y <= SS[x] ? P[x] : 0));
	if(y)
		ret = max(ret, f(x, y - 1) + (x <= TT[y] ? Q[y] : 0));
	bio[x][y] = 1; dp[x][y] = ret;
	return dp[x][y];
}
 
**/
 
void pocisti(int sad, ll trb){
	auto it = ostalo.lower_bound({sad, 0});
	while(it != ostalo.end() && trb > 0){
		if(it -> Y <= trb){
			trb -= it -> Y;
			del[it -> X] = mora[it -> X];
			it = ostalo.erase(it);
		}
		else{
			del[it -> X] -= trb;
			pii tmp = *it; 
			ostalo.erase(tmp);
			tmp.Y -= trb;
			ostalo.insert(tmp);
			return;
		}
	}
}
 
 
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= n;i++)
		scanf("%d%lld%d", A + i, S + i, P + i);
	for(int i = 1;i <= m;i++)
		scanf("%d%lld%d", B + i, T + i, Q + i);
	ll cur = 0; v.PB(cur);
	for(int i = 1;i <= m;i++)
		cur += B[i], v.PB(cur);
	cur = 0; v2.PB(cur);
	for(int i = 1;i <= n;i++){
		cur += A[i]; v2.PB(cur);
		if(S[i] < cur)
			P[i] = 0, S[i] = cur;
		SS[i] = upper_bound(v.begin(), v.end(), S[i] - cur) - v.begin() - 1;
	}
	cur = 0;
	for(int i = 1;i <= m;i++){
		cur += B[i];
		if(T[i] < cur)
			Q[i] = 0, T[i] = cur;
		TT[i] = upper_bound(v2.begin(), v2.end(), T[i] - cur) - v2.begin() - 1;
	}
	for(int i = m;i >= 1;i--){
		del[i] = Q[i], mora[i] = Q[i];
		if(TT[i]) 
			brisi[TT[i]].PB(i);
		else{
			mora[i] = 0;
		}
	}
	for(int i = m;i >= 1;i--){
		if(del[i] > mora[i]){
			ostalo.insert({i, del[i] - mora[i]});
		}
		if(del[i] < mora[i]){
			pocisti(i + 1, mora[i] - del[i]);
			del[i] = mora[i];
		}
	}
	//cur = 0;
	//for(int i = 1;i <= n;i++)
	//	printf("S[ %d ] = %d P[ %d ] = %d\n", i, SS[i], i, P[i]);
	//for(int i = 1;i <= m;i++)
	//	printf("T[ %d ] = %d Q[ %d ] = %d\n", i, TT[i], i, Q[i]);
	cur = 0;
	//for(int j = 0;j <= m;j++){
	//	cur += del[j];
	//	printf("%lld ", cur);
	//	if(j == m) printf("\n");
	//}
	//printf("OSTALO: \n"); for(pii tmp : ostalo) printf("%d %lld\n", tmp.X, tmp.Y);
	for(int i = 1;i <= n;i++){
		del[0] += P[i];
		del[SS[i] + 1] -= P[i];
		//printf("OSTALO: \n"); for(pii tmp : ostalo) printf("%d %lld\n", tmp.X, tmp.Y);
		if(mora[SS[i] + 1] > del[SS[i] + 1]){		
			pocisti(SS[i] + 2, mora[SS[i] + 1] - del[SS[i] + 1]);
			del[SS[i] + 1] = mora[SS[i] + 1];
		}
		if(del[SS[i] + 1] > mora[SS[i] + 1]){
			if(del[SS[i] + 1] + P[i] > mora[SS[i] + 1])
				ostalo.erase({SS[i] + 1, del[SS[i] + 1] + P[i] - mora[SS[i] + 1]});
			ostalo.insert({SS[i] + 1, del[SS[i] + 1] - mora[SS[i] + 1]});
		}
		//for(int j = 0;j <= m;j++)
		//	printf("mora[ %d ] = %lld , %lld\n", j, mora[j], del[j]);
		//ll cur = 0;
		//for(int j = 0;j <= m;j++){
		//	cur += del[j];
		//	printf("%lld ", cur);
		//	if(j == m) printf("\n");
		//}
		if(i == n){
			break;
		}
		for(int j : brisi[i]){
			//ll cur = 0;
			//for(int j = 0;j <= m;j++){
			//	cur += del[j];
			//	printf("%lld ", cur);
			//	if(j == m) printf("\n");
			//}
			if(del[j] > mora[j]){
				ostalo.erase({j, del[j] - mora[j]});
			}
			
			mora[j] = 0;  //printf("cistim %d\n", j);
			if(del[j] > mora[j]){
				ostalo.insert({j, del[j]});
			}
			else{
				//printf("fkt cistim %lld\n", -del[j]);
				pocisti(j + 1, -del[j]);
				del[j] = 0;
			}
		}
		
		//for(int j = 0;j <= m;j++){
		//	printf("%lld ", del[j]);
		//	if(j == m) printf("\n");
		//}
	}
	//printf("----------\n");
	//for(int i = 0;i <= n;i++){
	//	for(int j = 0;j <= m;j++)
	//		printf("%lld ", f(i, j));
	//	printf("\n");
	//}
	ll ans = 0;
	for(int i = 0;i <= m;i++)
		ans += del[i];
	printf("%lld\n", ans);
	//printf("%lld %lld\n", ans, f(n, m));
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", A + i, S + i, P + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", B + i, T + i, Q + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 393 ms 53156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23936 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23860 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 15 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23936 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23860 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 15 ms 23936 KB Output is correct
17 Correct 23 ms 24064 KB Output is correct
18 Correct 22 ms 24056 KB Output is correct
19 Incorrect 25 ms 24020 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23936 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23860 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 15 ms 23936 KB Output is correct
17 Correct 23 ms 24064 KB Output is correct
18 Correct 22 ms 24056 KB Output is correct
19 Incorrect 25 ms 24020 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23936 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23860 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 15 ms 23936 KB Output is correct
17 Correct 23 ms 24064 KB Output is correct
18 Correct 22 ms 24056 KB Output is correct
19 Incorrect 25 ms 24020 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23936 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23860 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 15 ms 23936 KB Output is correct
17 Correct 23 ms 24064 KB Output is correct
18 Correct 22 ms 24056 KB Output is correct
19 Incorrect 25 ms 24020 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 393 ms 53156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 393 ms 53156 KB Output isn't correct
2 Halted 0 ms 0 KB -