結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2020-03-11 20:54:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,547 bytes |
コンパイル時間 | 3,809 ms |
コンパイル使用メモリ | 128,016 KB |
最終ジャッジ日時 | 2025-01-09 06:19:38 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <iostream> #include <vector> #include <limits.h> #include <algorithm> #include <string> #include <math.h> #include <limits.h> #include <queue> #include <map> #include <set> #include <iomanip> #include <bitset> #include <cassert> #include <random> #include <functional> #include <stack> #include <iomanip> #include <cassert> //#include <boost/multiprecision/cpp_int.hpp> #include <complex> #include <cstdio> #include <list> //< in.txt > out.txt using namespace std; //std::ios::sync_with_stdio(false); //std::cin.tie(0); const long long MOD = 1e9 + 7; typedef long long LL; typedef long double LD; typedef pair<LL, LL> PLL; typedef pair<LD, LL> PDL; typedef pair<LD, LD> PDD; typedef vector<LL> VLL; typedef vector<VLL> VVLL; //typedef boost::multiprecision::cpp_int bigint; template<class T> void in(T& x) { cin >> x; } template<class T1, class T2> void in(pair<T1, T2>& p) { in(p.first); in(p.second); } template<class T> void in(vector<T>& v, LL st = -1, LL en = -1) { if (st == -1) { st = 0; en = v.size() - 1; } for (LL n = st; n <= en; n++) { in(v[n]); } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); LL B, N; cin >> B >> N; VLL A(N); in(A); LL SUM = 0; for (LL n = 0; n < N; n++)SUM += A[n]; sort(A.begin(), A.end(), [](LL a, LL b) { return a < b; }); LL c; if (N & 1) { c= A[N / 2]; } else { c= A[N / 2 - 1]; } if (SUM - N * c + B < 0)c = floor((LD)(SUM + B) / N); LL ans = 0; for (LL n = 0; n < N; n++) { ans += abs(A[n] - c); } cout << ans << "\n"; return 0; }