Submission #3441586


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n, k;
  scanf("%d %d", &n, &k);

  vector<LL> x(n);
  REP (i, n) {
    scanf("%lld", &x[i]);
  }

  int zp = distance(x.begin(), lower_bound(x.begin(), x.end(), 0));

  LL ans = pow(10, 18);
  FOR (i, max(0, zp - k), min(zp + 1, n - k + 1)) {
    LL t;
    if (x[i + k - 1] * x[i] < 0)
      t = x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i]));
    else
      t = max(abs(x[i + k - 1]), abs(x[i]));
    ans = min(ans, t);
  }
  cout << ans << endl;
}

Submission Info

Submission Time
Task C - Candles
User croonalullaby
Language C++14 (GCC 5.4.1)
Score 300
Code Size 833 Byte
Status AC
Exec Time 12 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &k);
                         ^
./Main.cpp:21:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &x[i]);
                         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 12
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 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 AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 12 ms 1024 KB
1_01.txt AC 12 ms 1024 KB
1_02.txt AC 12 ms 1024 KB
1_03.txt AC 12 ms 1024 KB
1_04.txt AC 12 ms 1024 KB
1_05.txt AC 12 ms 1024 KB
1_06.txt AC 12 ms 1024 KB
1_07.txt AC 12 ms 1024 KB