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 <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#define N 100001
#define min2(x,y) (x<y?x:y)
using namespace std;
typedef pair<int, pair<int, int> > pip;
int n, K;
long long out;
pair<int, int> in[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;
void f1() {
int x1 = n, x2 = 0, w = 0;
long long sum = 0, tot;
for (int i = 1; i <= n; i++) {
sum += (long long)in[i].first;
Q.push({ in[i].first,1 }), Q.push({ in[i].second,2 });
} tot = sum * 2;
while (!Q.empty()) {
sum += (long long)(Q.top().first - w)*(long long)(x2 - x1);
tot = min2(tot, sum * 2), w = Q.top().first;
if (Q.top().second == 1) x1--;
else x2++;
Q.pop();
} out += tot;
}
int main() {
// freopen("input.txt", "r", stdin);
int k, x, y;
char in_a, in_b;
scanf("%d %d ", &K, &k);
while (k--) {
scanf("%c %d %c %d ", &in_a, &x, &in_b, &y);
if (x > y) x += y, y = x - y, x -= y;
out += (long long)(y - x);
if (in_a != in_b) out++, in[++n] = { x,y };
}
if (K == 1) f1();
printf("%lld", out);
}
Compilation message (stderr)
bridge.cpp: In function 'int main()':
bridge.cpp:38:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d ", &K, &k);
^
bridge.cpp:40:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c %d %c %d ", &in_a, &x, &in_b, &y);
^
# | 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... |