結果
問題 | No.1391 ±1 Abs Sum |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-12 22:10:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 615 bytes |
コンパイル時間 | 2,130 ms |
コンパイル使用メモリ | 191,088 KB |
最終ジャッジ日時 | 2025-01-18 18:41:40 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 12 WA * 5 RE * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d%d",&N,&K); | ~~~~~^~~~~~~~~~~~~~ main.cpp:29:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | rep(i,N) scanf("%lld",&A[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;using LL=long long;using ULL=unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)int N,K;LL A[200000];LL solve(){LL ans=0;if(K*2<=N){rep(i,K) ans+=(A[i]-A[0])*2;rep(i,N) ans+=A[0]-A[i];return ans;}LL pibot = (N-K-K-1)/2;LL x=A[pibot];rep(i,pibot) ans+=(x-A[i])*2;rep(i,K) ans+=(A[i]-x)*2;rep(i,N) ans+=x-A[i];return ans;}int main(){scanf("%d%d",&N,&K);rep(i,N) scanf("%lld",&A[i]);LL ans=solve();reverse(A,A+N); rep(i,N) A[i]=-A[i];ans=min(ans,solve());printf("%lld\n",ans);return 0;}