結果
問題 | No.3016 ハチマキおじさん |
ユーザー |
![]() |
提出日時 | 2025-01-25 13:48:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 1,245 bytes |
コンパイル時間 | 4,975 ms |
コンパイル使用メモリ | 282,324 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2025-01-25 23:00:08 |
合計ジャッジ時間 | 8,059 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define For(i, a, b) for(int i = (a); i < (b); i++)#define rep(i, n) For(i, 0, n)#define rFor(i, a, b) for(int i = (a); i >= (b); i--)#define ALL(v) (v).begin(), (v).end()#define rALL(v) (v).rbegin(), (v).rend()using lint = long long;using ld = long double;int INF = 2000000000;lint LINF = 1000000000000000000;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;vector<lint> a(n), b(n - 1);rep(i, n) {cin >> a[i];}rep(i, n - 1) {cin >> b[i];}sort(ALL(a));sort(ALL(b));lint init = 0;rep(i, n - 1) {init += abs(a[i + 1] - b[i]);}lint unsat = init;lint cur = unsat;For(i, 1, n) {cur -= abs(a[i] - b[i - 1]);cur += abs(a[i - 1] - b[i - 1]);unsat = min(unsat, cur);}set<lint> ans;lint now = init;rep(i, n) {if (i > 0) {now -= abs(a[i] - b[i - 1]);now += abs(a[i - 1] - b[i - 1]);}if (now == unsat) {ans.insert(a[i]);}}cout << ans.size() << "\n";for (auto x : ans) {cout << x << " ";}cout << "\n";}