This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5;
int k, n, s[N + 5], t[N + 5];
char p[N + 5], q[N + 5];
namespace sub2 {
void main(int n, int k, int s[], int t[], char p[], char q[]) {
vector<int> arr;
int init = 0;
for (int i = 1; i <= n; i++) {
if (p[i] == q[i]) init += abs(s[i] - t[i]);
else arr.push_back(s[i]), arr.push_back(t[i]), init++;
}
sort(arr.begin(), arr.end());
int ans = 1e18, prefix = 0, suffix = accumulate(arr.begin(), arr.end(), 0ll);
for (int i = 0; i < arr.size(); i++) {
prefix += arr[i], suffix -= arr[i];
ans = min(ans, (i + 1)*arr[i] - prefix + suffix - ((int)arr.size() - 1 - i)*arr[i]);
}
cout << init + ans << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> k >> n;
for (int i = 1; i <= n; i++) cin >> p[i] >> s[i] >> q[i] >> t[i];
if (k == 1) sub2::main(n, k, s, t, p, q);
else cout << 0 << '\n';
return 0;
}
Compilation message (stderr)
bridge.cpp: In function 'void sub2::main(long long int, long long int, long long int*, long long int*, char*, char*)':
bridge.cpp:22:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < arr.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |