結果
| 問題 |
No.370 道路の掃除
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2016-07-20 20:05:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 589 bytes |
| コンパイル時間 | 628 ms |
| コンパイル使用メモリ | 64,752 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 17:55:53 |
| 合計ジャッジ時間 | 1,819 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d",&e);
| ~~~~~^~~~~~~~~
ソースコード
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int n,m;
scanf("%d %d",&n,&m);
std::vector<int> vec;
for(int i=0;i<m;i++){
int e;
scanf("%d",&e);
vec.push_back(e);
}
std::sort(vec.begin(),vec.end());
int ans=-1;
for(int i=0;i+n-1<m;i++){
int p1=vec[i];
int p2=vec[i+n-1];
int t;
if(p2<=0){
t=-p1;
}else if(0<=p1){
t=p2;
}else{
int t1=-p1*2+p2;
int t2=-p1+p2*2;
t=std::min(t1,t2);
}
if(ans==-1){
ans=t;
}else{
ans=std::min(t,ans);
}
}
printf("%d\n",ans);
return 0;
}
horiesiniti