Submission #568725

#TimeUsernameProblemLanguageResultExecution timeMemory
568725joelauReconstruction Project (JOI22_reconstruction)C++14
0 / 100
5017 ms6928 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...