Submission #23985

# Submission time Handle Problem Language Result Execution time Memory
23985 2017-05-28T14:52:18 Z gs14004 Long Distance Coach (JOI17_coach) C++11
100 / 100
639 ms 14820 KB
#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<lint, lint> pi;

lint x, n, m, w, t;
lint s[200005], dp[200005], ps[200005];
pi a[200005];
int nxt[200005];

lint get(lint e, lint x){
	return (e - x + t) / t;
}

vector<pi> v;
vector<pi> stk;

llf crs(pi x, pi y){
	return (llf)(y.second - x.second) / (x.first - y.first);
}

void add_line(lint x, lint y){
	stk.insert(lower_bound(stk.begin(), stk.end(), pi(x, y)), pi(x, y));
	if(stk.size() >= 500){
		vector<pi> nxt(v.size() + stk.size());
		merge(v.begin(), v.end(), stk.begin(), stk.end(), nxt.begin());
		v.clear();
		stk.clear();
		for(auto &i : nxt){
			if(!v.empty() && v.back().first == i.first) continue;
			while(v.size() >= 2 && crs(v[v.size()-2], v.back()) < crs(v.back(), i)){
				v.pop_back();
			}
			v.push_back(i);
		}
	}
}

lint query(int x){
	lint ans = 4e18;
	for(auto &i : stk) ans = min(ans, i.first * x + i.second);
	if(!v.empty()){
		int s = 0, e = v.size() - 1;
		while(s != e){
			int m = (s+e)/2;
			if(v[m].first * x + v[m].second < v[m+1].first * x + v[m+1].second) e = m;
			else s = m+1;
		}
		ans = min(ans, v[s].first * x + v[s].second);
	}
	return ans;
}

int main(){
	cin >> x >> n >> m >> w >> t;
	for(int i=0; i<n; i++){
		scanf("%lld",&s[i]);
	}
	s[n] = x;
	n++;
	sort(s, s+n, [&](const lint &a, const lint &b){
		return a%t < b%t;
	});
	for(int i=0; i<m; i++){
		scanf("%lld %lld",&a[i].first,&a[i].second);
	}
	sort(a, a+m);
	for(int i=m-1; i>=0; i--){
		ps[i] = ps[i+1] + a[i].second;
	}
	int p = m;
	for(int i=n-1; i>=0; i--){
		while(p > 0 && a[p-1].first > s[i] % t){
			p--;
		}
		nxt[i] = p;
	}
	lint aux = 0;
	p = n;
	for(int i=m-1; i>=0; i--){
		while(p > 0 && nxt[p-1] == i+1){
			p--;
			dp[p] = aux - ps[i+1];
			add_line((s[p] / t) * w, dp[p] + (s[p] / t) * w * nxt[p]);
		}
		aux += get(x, a[i].first) * w;
		aux = min(aux, query(-i) + ps[i]);
	}
	cout << aux + get(x, 0) * w;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:58:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&s[i]);
                      ^
coach.cpp:66:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&a[i].first,&a[i].second);
                                              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10616 KB Output is correct
2 Correct 0 ms 10616 KB Output is correct
3 Correct 0 ms 10616 KB Output is correct
4 Correct 0 ms 10616 KB Output is correct
5 Correct 0 ms 10616 KB Output is correct
6 Correct 0 ms 10616 KB Output is correct
7 Correct 0 ms 10616 KB Output is correct
8 Correct 0 ms 10616 KB Output is correct
9 Correct 0 ms 10616 KB Output is correct
10 Correct 0 ms 10616 KB Output is correct
11 Correct 0 ms 10616 KB Output is correct
12 Correct 0 ms 10616 KB Output is correct
13 Correct 0 ms 10616 KB Output is correct
14 Correct 0 ms 10616 KB Output is correct
15 Correct 0 ms 10616 KB Output is correct
16 Correct 0 ms 10616 KB Output is correct
17 Correct 0 ms 10616 KB Output is correct
18 Correct 0 ms 10616 KB Output is correct
19 Correct 0 ms 10616 KB Output is correct
20 Correct 0 ms 10616 KB Output is correct
21 Correct 0 ms 10616 KB Output is correct
22 Correct 0 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10616 KB Output is correct
2 Correct 0 ms 10616 KB Output is correct
3 Correct 0 ms 10616 KB Output is correct
4 Correct 0 ms 10616 KB Output is correct
5 Correct 0 ms 10616 KB Output is correct
6 Correct 0 ms 10616 KB Output is correct
7 Correct 0 ms 10616 KB Output is correct
8 Correct 0 ms 10616 KB Output is correct
9 Correct 0 ms 10616 KB Output is correct
10 Correct 0 ms 10616 KB Output is correct
11 Correct 0 ms 10616 KB Output is correct
12 Correct 0 ms 10616 KB Output is correct
13 Correct 0 ms 10616 KB Output is correct
14 Correct 0 ms 10616 KB Output is correct
15 Correct 0 ms 10616 KB Output is correct
16 Correct 0 ms 10616 KB Output is correct
17 Correct 0 ms 10616 KB Output is correct
18 Correct 0 ms 10616 KB Output is correct
19 Correct 0 ms 10616 KB Output is correct
20 Correct 0 ms 10616 KB Output is correct
21 Correct 0 ms 10616 KB Output is correct
22 Correct 0 ms 10616 KB Output is correct
23 Correct 0 ms 10616 KB Output is correct
24 Correct 0 ms 10616 KB Output is correct
25 Correct 0 ms 10616 KB Output is correct
26 Correct 0 ms 10616 KB Output is correct
27 Correct 0 ms 10616 KB Output is correct
28 Correct 0 ms 10616 KB Output is correct
29 Correct 0 ms 10616 KB Output is correct
30 Correct 0 ms 10616 KB Output is correct
31 Correct 0 ms 10616 KB Output is correct
32 Correct 0 ms 10616 KB Output is correct
33 Correct 0 ms 10616 KB Output is correct
34 Correct 0 ms 10616 KB Output is correct
35 Correct 0 ms 10616 KB Output is correct
36 Correct 0 ms 10616 KB Output is correct
37 Correct 0 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10616 KB Output is correct
2 Correct 0 ms 10616 KB Output is correct
3 Correct 0 ms 10616 KB Output is correct
4 Correct 0 ms 10616 KB Output is correct
5 Correct 0 ms 10616 KB Output is correct
6 Correct 0 ms 10616 KB Output is correct
7 Correct 0 ms 10616 KB Output is correct
8 Correct 0 ms 10616 KB Output is correct
9 Correct 0 ms 10616 KB Output is correct
10 Correct 0 ms 10616 KB Output is correct
11 Correct 0 ms 10616 KB Output is correct
12 Correct 0 ms 10616 KB Output is correct
13 Correct 0 ms 10616 KB Output is correct
14 Correct 0 ms 10616 KB Output is correct
15 Correct 0 ms 10616 KB Output is correct
16 Correct 0 ms 10616 KB Output is correct
17 Correct 0 ms 10616 KB Output is correct
18 Correct 0 ms 10616 KB Output is correct
19 Correct 0 ms 10616 KB Output is correct
20 Correct 0 ms 10616 KB Output is correct
21 Correct 0 ms 10616 KB Output is correct
22 Correct 0 ms 10616 KB Output is correct
23 Correct 0 ms 10616 KB Output is correct
24 Correct 0 ms 10616 KB Output is correct
25 Correct 0 ms 10616 KB Output is correct
26 Correct 0 ms 10616 KB Output is correct
27 Correct 0 ms 10616 KB Output is correct
28 Correct 0 ms 10616 KB Output is correct
29 Correct 0 ms 10616 KB Output is correct
30 Correct 0 ms 10616 KB Output is correct
31 Correct 0 ms 10616 KB Output is correct
32 Correct 0 ms 10616 KB Output is correct
33 Correct 0 ms 10616 KB Output is correct
34 Correct 0 ms 10616 KB Output is correct
35 Correct 0 ms 10616 KB Output is correct
36 Correct 0 ms 10616 KB Output is correct
37 Correct 0 ms 10616 KB Output is correct
38 Correct 3 ms 10616 KB Output is correct
39 Correct 3 ms 10616 KB Output is correct
40 Correct 3 ms 10616 KB Output is correct
41 Correct 3 ms 10616 KB Output is correct
42 Correct 3 ms 10616 KB Output is correct
43 Correct 3 ms 10616 KB Output is correct
44 Correct 3 ms 10616 KB Output is correct
45 Correct 3 ms 10616 KB Output is correct
46 Correct 3 ms 10756 KB Output is correct
47 Correct 3 ms 10616 KB Output is correct
48 Correct 3 ms 10616 KB Output is correct
49 Correct 3 ms 10616 KB Output is correct
50 Correct 3 ms 10616 KB Output is correct
51 Correct 3 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10616 KB Output is correct
2 Correct 0 ms 10616 KB Output is correct
3 Correct 0 ms 10616 KB Output is correct
4 Correct 0 ms 10616 KB Output is correct
5 Correct 0 ms 10616 KB Output is correct
6 Correct 0 ms 10616 KB Output is correct
7 Correct 0 ms 10616 KB Output is correct
8 Correct 0 ms 10616 KB Output is correct
9 Correct 0 ms 10616 KB Output is correct
10 Correct 0 ms 10616 KB Output is correct
11 Correct 0 ms 10616 KB Output is correct
12 Correct 0 ms 10616 KB Output is correct
13 Correct 0 ms 10616 KB Output is correct
14 Correct 0 ms 10616 KB Output is correct
15 Correct 0 ms 10616 KB Output is correct
16 Correct 0 ms 10616 KB Output is correct
17 Correct 0 ms 10616 KB Output is correct
18 Correct 0 ms 10616 KB Output is correct
19 Correct 0 ms 10616 KB Output is correct
20 Correct 0 ms 10616 KB Output is correct
21 Correct 0 ms 10616 KB Output is correct
22 Correct 0 ms 10616 KB Output is correct
23 Correct 0 ms 10616 KB Output is correct
24 Correct 0 ms 10616 KB Output is correct
25 Correct 0 ms 10616 KB Output is correct
26 Correct 0 ms 10616 KB Output is correct
27 Correct 0 ms 10616 KB Output is correct
28 Correct 0 ms 10616 KB Output is correct
29 Correct 0 ms 10616 KB Output is correct
30 Correct 0 ms 10616 KB Output is correct
31 Correct 0 ms 10616 KB Output is correct
32 Correct 0 ms 10616 KB Output is correct
33 Correct 0 ms 10616 KB Output is correct
34 Correct 0 ms 10616 KB Output is correct
35 Correct 0 ms 10616 KB Output is correct
36 Correct 0 ms 10616 KB Output is correct
37 Correct 0 ms 10616 KB Output is correct
38 Correct 3 ms 10616 KB Output is correct
39 Correct 3 ms 10616 KB Output is correct
40 Correct 3 ms 10616 KB Output is correct
41 Correct 3 ms 10616 KB Output is correct
42 Correct 3 ms 10616 KB Output is correct
43 Correct 3 ms 10616 KB Output is correct
44 Correct 3 ms 10616 KB Output is correct
45 Correct 3 ms 10616 KB Output is correct
46 Correct 3 ms 10756 KB Output is correct
47 Correct 3 ms 10616 KB Output is correct
48 Correct 3 ms 10616 KB Output is correct
49 Correct 3 ms 10616 KB Output is correct
50 Correct 3 ms 10616 KB Output is correct
51 Correct 3 ms 10616 KB Output is correct
52 Correct 393 ms 10616 KB Output is correct
53 Correct 409 ms 10616 KB Output is correct
54 Correct 363 ms 10616 KB Output is correct
55 Correct 346 ms 10616 KB Output is correct
56 Correct 366 ms 10616 KB Output is correct
57 Correct 353 ms 10616 KB Output is correct
58 Correct 319 ms 10616 KB Output is correct
59 Correct 369 ms 10616 KB Output is correct
60 Correct 363 ms 10616 KB Output is correct
61 Correct 376 ms 10616 KB Output is correct
62 Correct 349 ms 10616 KB Output is correct
63 Correct 639 ms 14820 KB Output is correct
64 Correct 166 ms 10616 KB Output is correct
65 Correct 473 ms 10616 KB Output is correct
66 Correct 459 ms 10616 KB Output is correct
67 Correct 463 ms 10616 KB Output is correct
68 Correct 483 ms 10616 KB Output is correct
69 Correct 463 ms 10616 KB Output is correct
70 Correct 406 ms 10616 KB Output is correct
71 Correct 376 ms 10616 KB Output is correct
72 Correct 379 ms 10616 KB Output is correct
73 Correct 383 ms 10616 KB Output is correct
74 Correct 389 ms 10616 KB Output is correct
75 Correct 409 ms 10616 KB Output is correct
76 Correct 339 ms 10616 KB Output is correct
77 Correct 363 ms 10616 KB Output is correct
78 Correct 386 ms 10616 KB Output is correct
79 Correct 333 ms 10616 KB Output is correct
80 Correct 356 ms 10616 KB Output is correct