QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#61785 | #2541. Coins and Boxes | Pitiless0514 | TL | 3ms | 5428kb | C++14 | 2.5kb | 2022-11-14 20:19:33 | 2022-11-14 20:19:35 |
Judging History
answer
// 德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱
// 德丽莎的可爱在于德丽莎很可爱,德丽莎为什么很可爱呢,这是因为德丽莎很可爱!
// 没有力量的理想是戏言,没有理想的力量是空虚
#include <bits/stdc++.h>
#define LL long long
#define int long long
using namespace std;
namespace IO {
const int SZ = (1 << 21) + 1;
char ib[SZ], *iS, *iT, ob[SZ], *oS = ob, *oT = oS + SZ - 1, cc, qu[55]; int ff, qr;
#define gc() (iS == iT ? (iT = (iS = ib) + fread(ib, 1, SZ, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
// #define gc() getchar()
void flush() { fwrite(ob, 1, oS - ob, stdout), oS = ob; }
void putc(char x) { *oS++ = x; if (oS == oT) flush(); }
template <class I>
void read(I &x) {
for (ff = 1, cc = gc(); cc < '0' || cc > '9'; cc = gc()) if (cc == '-') ff = -1;
for (x = 0; cc <= '9' && cc >= '0'; cc = gc()) x = x * 10 + (cc & 15);
x *= ff;
}
template <class I, class... Y>
void read(I &t, Y &... a) { read(t), read(a...); }
template <class I>
void write(I x) {
if (!x) putc('0');
if (x < 0) putc('-'), x = -x;
while (x) qu[++qr] = x % 10 + '0', x /= 10;
while (qr) putc(qu[qr --]);
}
} using namespace IO;
template<class T> bool chkmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chkmax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define repd(i, l, r) for (int i = (l); i >= (r); i--)
#define REP(i, l, r) for (int i = (l); i < (r); i++)
bool o1;
const int N = 2e5, inf = 1e17;
int n;
pair <int,int> a[N];
void solve() {
read(n);
rep (i, 1, n) read(a[i].first), a[i].second = -1;
rep (i, n + 1, 2 * n) read(a[i].first), a[i].second = 1;
n *= 2;
sort(a + 1, a + n + 1);
int now = 0, tot = 0, ans = inf;
a[n + 1] = a[n];
rep (i, 0, n) {
now += a[i].second;
if (now < 0) tot += (a[i + 1].first - a[i].first) * 2;
ans = min(ans, tot + a[n].first - a[i + 1].first);
}
// cout << ans << "\n";
ans += a[n].first;
cout << ans;
}
bool o2;
signed main () {
#ifdef LOCAL_DEFINE
cerr << "Memory elapsed: " << 1.0 * (&o1 - &o2) / 1024 / 1024 << ".Mib\n";
freopen("1.in", "r", stdin);
freopen("1.ans", "w", stdout);
#endif
int T = 1; while (T--) solve();
flush();
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
// Think twice, code once
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 5428kb
input:
4 1 6 7 12 3 5 10 11
output:
21
result:
ok answer is '21'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5388kb
input:
2 1 2 1 1000000000
output:
1999999998
result:
ok answer is '1999999998'
Test #3:
score: -100
Time Limit Exceeded
input:
100000 967 3246 9492 10300 15195 16650 26911 54855 83695 112841 125511 137160 153051 155859 177924 187843 214838 219388 247276 249612 250188 253873 257830 261805 281312 297030 298332 325904 333218 339683 374111 387794 396645 403705 426710 436137 463368 481801 501933 509267 511332 515225 515629 51686...