#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)2e5 + 12, b = 18;
const ll inf = (ll)1e10;
int n, m, q, s[N];
vector<int> g[N];
void test() {
cin >> n >> m >> q;
vector<pair<int, int>> vals;
for(int i = 1; i <= n; i++) {
cin >> s[i];
vals.push_back({s[i], i});
}
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
sort(vals.begin(), vals.end());
ll res = 0;
ll sub = 0;
for(int i = 0; i < n; ) {
int j = i, c = 0;
while(j < n && vals[j].first == vals[i].first) {
c += (int)g[vals[j].second].size() - 1;
j++;
}
res += m * 1ll * (vals[i].first - sub);
sub += (vals[i].first - sub);
m -= c;
i = j;
}
cout << res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |