# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547058 | nonsensenonsense1 | Sightseeing in Kyoto (JOI22_kyoto) | C++17 | 564 ms | 23272 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 <cstdio>
#include <set>
struct frac {
int a, b;
frac(int a_ = 0, int b_ = 0) {
a = a_;
b = b_;
}
};
bool operator<(frac a, frac b) {
return (long long)a.a * b.b < (long long)b.a * a.b;
}
const int N = 100000;
int h, w, a[N], b[N];
bool rmx[N], rmy[N];
std::set<std::pair<frac, int> > st;
std::set<int> x, y;
int main() {
scanf("%d%d", &h, &w);
for (int i = 0; i < h; ++i) {
x.insert(i);
scanf("%d", a + i);
if (i) st.insert(std::make_pair(frac(a[i - 1] - a[i], 1), i));
}
for (int i = 0; i < w; ++i) {
y.insert(i);
scanf("%d", b + i);
if (i) st.insert(std::make_pair(frac(b[i - 1] - b[i], 1), h + i));
}
long long ans = 0;
while (st.size()) {
int pos = st.begin()->second;
st.erase(st.begin());
if (pos < h) {
if (!rmx[pos]) {
rmx[pos] = 1;
x.erase(pos);
std::set<int>::iterator it = x.lower_bound(pos);
if (it == x.end()) ans += (long long)b[*prev(y.end())] * (pos - *prev(it));
else st.insert(std::make_pair(frac(a[*prev(it)] - a[*it], *it - *prev(it)), *it));
}
} else {
pos -= h;
if (!rmy[pos]) {
rmy[pos] = 1;
y.erase(pos);
std::set<int>::iterator it = y.lower_bound(pos);
if (it == y.end()) ans += (long long)a[*prev(x.end())] * (pos - *prev(it));
else st.insert(std::make_pair(frac(b[*prev(it)] - b[*it], *it - *prev(it)), h + *it));
}
}
}
printf("%lld\n", ans);
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... |