답안 #884209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884209 2023-12-06T18:16:15 Z DAleksa Long Distance Coach (JOI17_coach) C++17
0 / 100
2 ms 12636 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

struct Line {
    int a;
    int b;
    long long eval(int x) { return a * 1LL * x + b; }
};

const int N = 2e5 + 10;

long long X, T;
int n, m, W;
long long a[N];
long long b[N], B[N];
long long c[N], C[N];
int order[N];
long long pref[N];
int dp[N];
long long ind[N];
long long cnt[N];
vector<Line> lines;
vector<long long> all;
map<long long, int> start_to_index;

long long get(int x) {
    long long ans = 1e18;
    for(Line l : lines) ans = min(ans, l.eval(x));
    return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> X >> n >> m >> W >> T;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
	for(int i = 1; i <= m; i++) order[i] = i;
	sort(order + 1, order + m + 1, [&](int i, int j) {
		return B[i] < B[j];
	});
	for(int i = 1; i <= m; i++) {
		b[i] = B[order[i]];
		c[i] = C[order[i]];
		all.push_back(b[i]);
		start_to_index[b[i]] = i;
		pref[i] = pref[i - 1] + c[i];
		cnt[i] = X / T + (b[i] <= X % T);
		ind[i] = -1;
	}
	sort(all.begin(), all.end());
	n++;
	a[n] = X;
//	for(int i : all) cout << i << " ";
//	cout << "\n";
	for(int i = n; i >= 1; i--) {
		int temp = a[i] % T;
		int index = lower_bound(all.begin(), all.end(), temp) - all.begin();
		index--;
		if(index == -1) continue;
		ind[start_to_index[(a[i] - (temp - all[index])) % T]] = a[i] - (temp - all[index]);
	}
//	for(int i = 1; i <= m; i++) cout << ind[i] << " ";
//	cout << "\n";
//    for(int i = 1; i <= m; i++) cout << cnt[i] << " ";
//    cout << "\n";
	for(int i = 1; i <= m; i++) {
		dp[i] = dp[i - 1] + W * cnt[i];
		if(ind[i] != -1) dp[i] = min(dp[i], (int)get(W * (ind[i] / T)) + pref[i] + W * i * (ind[i] / T));
		lines.push_back({-i, dp[i] - pref[i]});
	}
//	for(int i = 1; i <= m; i++) cout << dp[i] << " ";
//	cout << "\n";
	cout << (long long)(dp[m] + (X / T + 1) * W);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -