Contest Duration: - (local time) (100 minutes) Back to Home

Submission #3079230

Source Code Expand

Copy
```#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, k;
ll ans;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> k;
vector<ll> x(n);
int l = 0, r = 0;
rep(i, 0, n) {
cin >> x[i];
if (x[i] <= 0) l = i, r = i+1;
}
while (l >= 0 && r < n-1 && r - l < k-1) {
if (l - 1 >= 0 && r + 1 < n && abs(x[r + 1]) >= abs(x[l - 1])) l--;
else r++;
}
if (l < 0) ans = x[r];
else if (r >= n) ans = x[l];
else if (x[l] * x[r] >= 0) ans = max(x[l], x[r]);
else ans = min(2 * abs(x[l]) + abs(x[r]), 2 * abs(x[r]) + abs(x[l]));
cout << ans << endl;
return 0;
}
```

#### Submission Info

Submission Time 2018-08-25 22:36:33+0900 C - Candles kage C++14 (GCC 5.4.1) 0 1322 Byte WA 12 ms 1024 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
 AC × 4
 AC × 7 WA × 5
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 WA 11 ms 1024 KB
1_02.txt WA 11 ms 1024 KB
1_03.txt WA 11 ms 1024 KB
1_04.txt AC 11 ms 1024 KB
1_05.txt AC 11 ms 1024 KB
1_06.txt WA 11 ms 1024 KB
1_07.txt WA 11 ms 1024 KB