結果
| 問題 |
No.370 道路の掃除
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-27 18:38:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 456 bytes |
| コンパイル時間 | 2,331 ms |
| コンパイル使用メモリ | 196,840 KB |
| 最終ジャッジ日時 | 2025-01-10 02:32:44 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | int n,m; scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | rep(i,m) scanf("%d",&x[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int main(){
int n,m; scanf("%d%d",&n,&m);
vector<int> x(m);
rep(i,m) scanf("%d",&x[i]);
sort(x.begin(),x.end());
int ans=INF;
rep(i,m-n+1){
if(x[i]>=0){
ans=min(ans,x[i+n-1]);
}
else if(x[i+n-1]<0){
ans=min(ans,-x[i]);
}
else{
ans=min({ans,-2*x[i]+x[i+n-1],2*x[i+n-1]-x[i]});
}
}
printf("%d\n",ans);
return 0;
}