結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-23 12:46:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 556 bytes |
| コンパイル時間 | 1,728 ms |
| コンパイル使用メモリ | 201,004 KB |
| 実行使用メモリ | 7,840 KB |
| 最終ジャッジ日時 | 2025-11-26 11:43:55 |
| 合計ジャッジ時間 | 2,668 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
using lint=long long;
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint X,n;std::cin>>X>>n;
std::vector<lint>a(n);
for(lint&x:a)std::cin>>x;
std::sort(a.begin(),a.end());
lint sum=std::accumulate(a.begin(),a.end(),0ll);
lint med=a.at(n/2);
if(sum+X<med*n){
med=(sum+X)/n;
}
std::cout<<std::accumulate(
a.begin(),a.end(),0ll,[med](lint x,lint y){return x+std::abs(y-med);})<<'\n';
}
ngtkana