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>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
#define pdd pair <double, double>
using namespace std;
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 1e6+1010;
void solve(){
int k, n, ans = 0;
cin >> k >> n;
vector <pii> a;
for (int i = 0; i < n; ++i){
char c1, c2;
int x, y;
cin >> c1 >> x >> c2 >> y;
if (c1 == c2){
ans += abs(x-y);
continue;
}
if (x > y) swap(x, y);
a.pb({x, y});
}
n = a.size();
ans += n;
if (k == 1){
vector <int> b;
for (auto i : a){
b.pb(i.ff);
b.pb(i.ss);
}
sort(all(b));
for (int i = 0; i < n; ++i) ans -= b[i];
for (int i = n; i < 2*n; ++i) ans += b[i];
cout << ans;
return;
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--){
solve();
cout << '\n';
}
}
# | 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... |