Submission #3072870


Source Code Expand

Copy
#include<bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  int N, K, X[100000];
  cin >> N >> K;
  vector< int > pos, neg;
  for(int i = 0; i < N; i++) {
    cin >> X[i];
  }
  int ret = 1 << 30;
  for(int i = 0; i <= N - K; i++) {
    int L = X[i], R = X[i + K - 1];
    if(R < 0) ret = min(ret, -L);
    else if(L >= 0) ret = min(ret, R);
    else ret = min(ret, min(2 * -L + R, 2 * R - L));
  }
  cout << ret << endl;
}

Submission Info

Submission Time
Task C - Candles
User ei13333
Language C++14 (GCC 5.4.1)
Score 300
Code Size 472 Byte
Status
Exec Time 53 ms
Memory 640 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 300 / 300 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
0_03.txt 1 ms 256 KB
1_00.txt 51 ms 640 KB
1_01.txt 51 ms 640 KB
1_02.txt 52 ms 640 KB
1_03.txt 53 ms 640 KB
1_04.txt 49 ms 640 KB
1_05.txt 50 ms 640 KB
1_06.txt 49 ms 640 KB
1_07.txt 51 ms 640 KB