답안 #108834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108834 2019-05-02T09:13:56 Z antimirage Two Dishes (JOI19_dishes) C++14
0 / 100
566 ms 38392 KB
/**
	Elohim Essaim, Elohim Essaim I implore you...
**/
#include <bits/stdc++.h>
 
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define int long long
 
using namespace std;
 
const int N = 1e6 + 5;
 
int n, m, a[N], b[N], p[N], q[N];

long long ans, mx[N * 4], lz[N * 4], inf = 1e18, s[N], t[N], pr1[N], pr2[N];

map < pair<int, int>, long long> mp;
 
void push(int v, int tl, int tr){
	
	if (lz[v]){
		mx[v] += lz[v];
		
		if (tl != tr)
			lz[v + v] += lz[v],
			lz[v + v + 1] += lz[v];
			
		lz[v] = 0;
	}
}
 
void add (int l, int r, long long val, int v = 1, int tl = 0, int tr = n)
{
	push(v, tl, tr);
	
	if (l > tr || tl > r) return;
	
	if (l <= tl && tr <= r)
	{
		lz[v] = val;
		push(v, tl , tr);
		return;
	}
	int tm = (tl + tr) >> 1;
	
	add(l, r, val, v + v, tl, tm);
	add(l, r, val, v + v + 1, tm + 1, tr);
	
	mx[v] = max(mx[v + v], mx[v + v + 1]);
}
long long get (int l, int r, int v = 1, int tl = 0, int tr = n)
{
	push(v, tl, tr);
	if (l > tr || tl > r || l > r)
		return -inf;
		
	if (l <= tl && tr <= r)
		return mx[v];
	
	int tm = (tl + tr) >> 1;
	
	return max( get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr) );
}
void update (int pos, long long val, int v = 1, int tl = 0, int tr = n)
{
	push(v, tl, tr);
	
	if (tl == tr)
		mx[v] = max(mx[v], val);
	else{
		int tm = (tl + tr) >> 1;
		
		if (pos <= tm)
			update(pos, val, v + v, tl, tm);
		else
			update(pos, val, v + v + 1, tm + 1, tr);
			
		mx[v] = max( mx[v + v], mx[v + v + 1] );
	}
}
main(){
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++){
		
		scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
		pr1[i] = pr1[i - 1] + a[i];
	}	
	for (int i = 1; i <= m; i++){
		
		scanf("%lld%lld%lld", &b[i], &t[i], &q[i]);
		pr2[i] = pr2[i - 1] + b[i];
		ans += q[i];
	}
	for (int i = 1; i <= n; i++)
	{
		if (pr1[i] > s[i]) continue;
		
		int j = upper_bound( pr2 + 1, pr2 + 1 + m, s[i] - pr1[i] ) - pr2 - 1;
		
		mp[ mk(j, -i) ] += p[i];
	}	
	for (int i = 1; i <= m; i++)
	{
		if (pr2[i] > t[i]){
			ans -= q[i];
			continue;
		}
		int j = upper_bound( pr1 + 1, pr1 + 1 + n, t[i] - pr2[i] ) - pr1 - 1;
		
		mp[ mk(i - 1, -j - 1) ] -= q[i];
	}
	for (auto it : mp)
	{
		update( -it.fr.sc, get(0, (-it.fr.sc) - 1) );
		add( -it.fr.sc, n, it.sc);
	}
	cout << mx[1] + ans << endl;
}
/**
4
5
7 3 1
2 12 11
1 3 12
7 13 13
2 4 13
3 11 14
9 8 9
7 2 10
13 2 13


**/

Compilation message

dishes.cpp:85:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
dishes.cpp: In function 'int main()':
dishes.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &a[i], &s[i], &p[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &b[i], &t[i], &q[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 35448 KB Output is correct
2 Incorrect 566 ms 38392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 2 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 2 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 2 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 2 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 2 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 35448 KB Output is correct
2 Incorrect 566 ms 38392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 35448 KB Output is correct
2 Incorrect 566 ms 38392 KB Output isn't correct
3 Halted 0 ms 0 KB -