Submission #3503293


Source Code Expand

Copy
#include <bits/stdc++.h>
#define rep(i,x,b) for(int i=x;i<(b);++i)
#define erep(i,x,b) for(int i=x;i<=(int)(b);++i)
#define per(i,x,b) for(int i=(x);i>(b);--i)
#define eper(i,x,b) for(int i=(x);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &x, const T &b) { if (x<b) { x = b; return 1; } return 0; }
template<class T>bool chmin(T &x, const T &b) { if (b<x) { x = b; return 1; } return 0; }
template<class T>void show(const vector<T> &x) { for (int i = 0; i < (int)x.size(); ++i) cout << x[i] << (i != (int)x.size()-1 ? " " : "\n"); }
template<class T>T gcd(T x, T b){ return b ? gcd(b, x % b) : x; }
template<class T>T lcm(T x, T b){ return x / gcd(x, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, k, x[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, 0, n) cin >> x[i];
    ll ans = INF;
    rep(l, 0, n - k + 1) {
      int r = l + k - 1;
      ans = min({ans, abs(x[l]) + abs(x[l] - x[r]), abs(x[r]) + abs(x[r] - x[l])});
    }
    cout << ans << endl;
    return 0;
}

Submission Info

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

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 10 ms 1024 KB
1_01.txt AC 11 ms 1024 KB
1_02.txt AC 11 ms 1024 KB
1_03.txt AC 11 ms 1024 KB
1_04.txt AC 10 ms 1024 KB
1_05.txt AC 10 ms 1024 KB
1_06.txt AC 10 ms 1024 KB
1_07.txt AC 11 ms 1024 KB