#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m,q;
vector<int> w[100005];
int idx[100005];
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>m;
int a,b,c;
rep(x,0,m){
cin>>a>>b>>c;
w[a].pub(c);
}
rep(x,1,n) sort(all(w[x]));
cin>>q;
while (q--){
int val;
cin>>val;
long long ans=0;
rep(x,1,n){
while (idx[x]+1<sz(w[x]) && abs(w[x][idx[x]+1]-val)<abs(w[x][idx[x]]-val)){
idx[x]++;
}
ans+=abs(w[x][idx[x]]-val);
}
cout<<ans<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2532 ms |
14184 KB |
Output is correct |
5 |
Correct |
2637 ms |
16632 KB |
Output is correct |
6 |
Correct |
2472 ms |
16616 KB |
Output is correct |
7 |
Correct |
2419 ms |
18500 KB |
Output is correct |
8 |
Correct |
1844 ms |
18776 KB |
Output is correct |
9 |
Correct |
1693 ms |
18556 KB |
Output is correct |
10 |
Correct |
2510 ms |
16612 KB |
Output is correct |
11 |
Correct |
1896 ms |
18628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |