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

Submission #3076508

Source Code Expand

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
cin.tie(0);
ios::sync_with_stdio(false);

ll n, k;
cin >> n >> k;

ll x[n];
ll zmcnt = 0;

rep(i, n){
cin >> x[i];
if(x[i] <= 0) zmcnt++;
}

if(zmcnt == 0){
cout << x[k-1]<< endl;
return 0;
}

ll plcnt = n - zmcnt;
ll pl[plcnt+1];
ll zm[zmcnt+1];

pl[0] = 0;
zm[0] = 0;
for(ll i = 0; i < zmcnt; i++) zm[i+1] = -x[zmcnt- i - 1];
for(ll i = 0; i < plcnt; i++) pl[i+1] = x[i + zmcnt];

/*
for(ll i = 0; i < zmcnt; i++) cout << zm[i+1] << ",";
cout << endl;
for(ll i = 0; i < plcnt; i++) cout << pl[i+1] << ",";
cout << endl;
*/

ll ans = 1e12;
for(int i = 0; i <= k; i++){
if(i <= plcnt && k-i <= zmcnt) {
// cout << i << "," << pl[i] << "," << zm[k-i] << endl;
ans = min(ans, pl[i] + zm[k-i] * 2);
ans = min(ans, pl[i] * 2 + zm[k-i]);
}
}

cout << ans << endl;
}```

#### Submission Info

Submission Time 2018-08-25 21:51:33+0900 C - Candles misora192 C++14 (GCC 5.4.1) 300 1135 Byte AC 11 ms 1792 KB

#### Test Cases

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