# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
660880 | danikoynov | Palembang Bridges (APIO15_bridge) | C++14 | 97 ms | 3548 KiB |
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>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 1e5 + 10;
struct work
{
ll x, y;
}w[maxn];
int k, n;
void solve()
{
cin >> k >> n;
ll ans = 0;
vector < ll > v;
for (int i = 1; i <= n; i ++)
{
char c1, c2;
cin >> c1 >> w[i].x >> c2 >> w[i].y;
if (w[i].x > w[i].y)
swap(w[i].x, w[i].y);
if (c1 == c2)
{
ans = ans + w[i].y - w[i].x;
i --;
n --;
}
else
{
v.push_back(w[i].y);
v.push_back(w[i].x);
ans ++;
}
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size() / 2; i ++)
ans = ans - (v[i]);
for (int i = v.size() / 2; i < v.size(); i ++)
ans = ans + v[i];
cout << ans << endl;
}
int main()
{
solve();
return 0;
}
Compilation message (stderr)
# | 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... |