#include <bits/stdc++.h>
using namespace std;
long long N,M,Q;
vector<long long> lst[505];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> M;
for (long long i = 0; i < M; ++i) {
long long u,v,w; cin >> u >> v >> w; u--, v--;
lst[u].push_back(w);
}
for (long long i = 0; i < N; ++i) sort(lst[i].begin(),lst[i].end());
cin >> Q;
while (Q--) {
long long x; cin >> x;
long long ans = 0;
for (long long i = 0; i < N-1; ++i) {
auto it = lower_bound(lst[i].begin(),lst[i].end(),x);
long long val = 4e18;
if (it != lst[i].end()) val = min(val,*it - x);
if (it != lst[i].begin()) val = min(val,x-*prev(it));
ans += val;
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
5017 ms |
6928 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |