結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
|
提出日時 | 2020-04-25 21:18:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 410 bytes |
コンパイル時間 | 2,374 ms |
コンパイル使用メモリ | 196,860 KB |
最終ジャッジ日時 | 2025-01-10 01:39:00 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | lint b; scanf("%lld",&b); | ~~~~~^~~~~~~~~~~ main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | rep(i,n) scanf("%lld",&c[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ lint b; scanf("%lld",&b); int n; scanf("%d",&n); vector<lint> c(n); rep(i,n) scanf("%lld",&c[i]); lint ub=(b+accumulate(c.begin(),c.end(),0LL))/n; sort(c.begin(),c.end()); lint med=c[n/2]; lint ans=0; rep(i,n) ans+=abs(c[i]-min(ub,med)); printf("%lld\n",ans); return 0; }