Submission #41565

# Submission time Handle Problem Language Result Execution time Memory
41565 2018-02-19T07:31:52 Z grumpy_gordon Arranging Tickets (JOI17_arranging_tickets) C++14
100 / 100
1181 ms 39260 KB
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
 
const int MAX_N = 2e5 + 100, MAX_M = 1e5 + 100, MAX_C = 1e9 + 100;
 
int N, M; ti Nr[MAX_M];
ll Sum[MAX_N], Temp[MAX_N], maxV;
bool isCan(ll use, ll lim) {
	ll up = lim - use;
	ll cnt = 0;
	priority_queue<pi> Q;
	for(int i=0; i<=N; i++) Temp[i] = 0;
	for(int i=1, j=0; i<=N; i++) {
		Temp[i] += Temp[i-1];
		while(j < M && get<0>(Nr[j]) == i) Q.push(pi(get<1>(Nr[j]), get<2>(Nr[j]))), j++;
		ll now = Sum[i] + Temp[i];
		while(!Q.empty() && now > up) {
			int y, c; tie(y, c) = Q.top(); Q.pop();
			if(y <= i) continue;
			int v = min((ll)c, (now - up + 1) / 2);
			Temp[i] -= 2 * v;
			Temp[y] += 2 * v;
			cnt += v;
			now -= 2 * v;
			if(c - v > 0) Q.push(pi(y, c-v));
		}
		if(now > up) return false;
		if(cnt > use) return false;
	}
	return true;
}
int main() {
	cin >> N >> M;
	for(int i=0; i<M; i++) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		if(x > y) swap(x, y);
		Nr[i] = ti(x, y, c);
		Sum[x] += c; Sum[y] -= c;
	}
	sort(Nr, Nr+M);
	for(int i=1; i<=N; i++) Sum[i] += Sum[i-1], maxV = max(maxV, Sum[i]);
 
	ll ans = -1;
	for(ll l=0, r=maxV; l<=r; ) {
		ll m = (l+r) >> 1;
		if(isCan(maxV-m, m) || isCan(maxV-m+1, m)) ans = m, r = m-1; else l = m+1;
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:47:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, c; scanf("%d%d%d", &x, &y, &c);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 772 KB Output is correct
19 Correct 2 ms 776 KB Output is correct
20 Correct 2 ms 780 KB Output is correct
21 Correct 2 ms 912 KB Output is correct
22 Correct 2 ms 912 KB Output is correct
23 Correct 2 ms 912 KB Output is correct
24 Correct 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 2 ms 912 KB Output is correct
27 Correct 2 ms 912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 772 KB Output is correct
19 Correct 2 ms 776 KB Output is correct
20 Correct 2 ms 780 KB Output is correct
21 Correct 2 ms 912 KB Output is correct
22 Correct 2 ms 912 KB Output is correct
23 Correct 2 ms 912 KB Output is correct
24 Correct 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 2 ms 912 KB Output is correct
27 Correct 2 ms 912 KB Output is correct
28 Correct 5 ms 956 KB Output is correct
29 Correct 6 ms 1060 KB Output is correct
30 Correct 5 ms 1060 KB Output is correct
31 Correct 6 ms 1152 KB Output is correct
32 Correct 6 ms 1152 KB Output is correct
33 Correct 6 ms 1164 KB Output is correct
34 Correct 3 ms 1200 KB Output is correct
35 Correct 6 ms 1232 KB Output is correct
36 Correct 5 ms 1268 KB Output is correct
37 Correct 3 ms 1332 KB Output is correct
38 Correct 3 ms 1368 KB Output is correct
39 Correct 3 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 772 KB Output is correct
19 Correct 2 ms 776 KB Output is correct
20 Correct 2 ms 780 KB Output is correct
21 Correct 2 ms 912 KB Output is correct
22 Correct 2 ms 912 KB Output is correct
23 Correct 2 ms 912 KB Output is correct
24 Correct 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 2 ms 912 KB Output is correct
27 Correct 2 ms 912 KB Output is correct
28 Correct 5 ms 956 KB Output is correct
29 Correct 6 ms 1060 KB Output is correct
30 Correct 5 ms 1060 KB Output is correct
31 Correct 6 ms 1152 KB Output is correct
32 Correct 6 ms 1152 KB Output is correct
33 Correct 6 ms 1164 KB Output is correct
34 Correct 3 ms 1200 KB Output is correct
35 Correct 6 ms 1232 KB Output is correct
36 Correct 5 ms 1268 KB Output is correct
37 Correct 3 ms 1332 KB Output is correct
38 Correct 3 ms 1368 KB Output is correct
39 Correct 3 ms 1404 KB Output is correct
40 Correct 243 ms 8608 KB Output is correct
41 Correct 247 ms 9992 KB Output is correct
42 Correct 205 ms 11388 KB Output is correct
43 Correct 256 ms 12880 KB Output is correct
44 Correct 265 ms 14400 KB Output is correct
45 Correct 256 ms 15832 KB Output is correct
46 Correct 201 ms 17016 KB Output is correct
47 Correct 68 ms 17456 KB Output is correct
48 Correct 79 ms 19012 KB Output is correct
49 Correct 64 ms 19012 KB Output is correct
50 Correct 60 ms 20540 KB Output is correct
51 Correct 66 ms 21884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 772 KB Output is correct
19 Correct 2 ms 776 KB Output is correct
20 Correct 2 ms 780 KB Output is correct
21 Correct 2 ms 912 KB Output is correct
22 Correct 2 ms 912 KB Output is correct
23 Correct 2 ms 912 KB Output is correct
24 Correct 2 ms 912 KB Output is correct
25 Correct 2 ms 912 KB Output is correct
26 Correct 2 ms 912 KB Output is correct
27 Correct 2 ms 912 KB Output is correct
28 Correct 5 ms 956 KB Output is correct
29 Correct 6 ms 1060 KB Output is correct
30 Correct 5 ms 1060 KB Output is correct
31 Correct 6 ms 1152 KB Output is correct
32 Correct 6 ms 1152 KB Output is correct
33 Correct 6 ms 1164 KB Output is correct
34 Correct 3 ms 1200 KB Output is correct
35 Correct 6 ms 1232 KB Output is correct
36 Correct 5 ms 1268 KB Output is correct
37 Correct 3 ms 1332 KB Output is correct
38 Correct 3 ms 1368 KB Output is correct
39 Correct 3 ms 1404 KB Output is correct
40 Correct 243 ms 8608 KB Output is correct
41 Correct 247 ms 9992 KB Output is correct
42 Correct 205 ms 11388 KB Output is correct
43 Correct 256 ms 12880 KB Output is correct
44 Correct 265 ms 14400 KB Output is correct
45 Correct 256 ms 15832 KB Output is correct
46 Correct 201 ms 17016 KB Output is correct
47 Correct 68 ms 17456 KB Output is correct
48 Correct 79 ms 19012 KB Output is correct
49 Correct 64 ms 19012 KB Output is correct
50 Correct 60 ms 20540 KB Output is correct
51 Correct 66 ms 21884 KB Output is correct
52 Correct 1181 ms 26080 KB Output is correct
53 Correct 771 ms 28176 KB Output is correct
54 Correct 1022 ms 30488 KB Output is correct
55 Correct 1134 ms 32860 KB Output is correct
56 Correct 877 ms 34944 KB Output is correct
57 Correct 1063 ms 36900 KB Output is correct
58 Correct 937 ms 38852 KB Output is correct
59 Correct 613 ms 39260 KB Output is correct