Submission #4025502
Source Code Expand
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<long> Xp, Xm; long x; for (int i = 0; i < N; i++) { cin >> x; if (x < 0) Xm.push_back(abs(x)); else if (0 < x) Xp.push_back(x); else K--; } if (Xm.size() == 0 && Xp.size() == 0) { cout << 0 << endl; return 0; } sort(Xm.begin(), Xm.end()); sort(Xp.begin(), Xp.end()); if (Xm.size() == 0) { cout << Xp[K-1] << endl; return 0; } if (Xp.size() == 0) { cout << Xm[K-1] << endl; return 0; } long ans = Xm.back() * 2 + Xp.back() * 2; for (int i = 0; i <= K; i++) { if (Xp.size() < i || Xm.size() < K-i) continue; long tmp1 = (i != 0) * Xp[i-1]; long tmp2 = (K-i != 0) * Xm[K-i-1]; ans = min({ans, tmp1*2 + tmp2, tmp1 + tmp2*2}); } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Candles |
User | skwbc |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 866 Byte |
Status | AC |
Exec Time | 44 ms |
Memory | 1656 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
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 | 41 ms | 1400 KB |
1_01.txt | AC | 44 ms | 1400 KB |
1_02.txt | AC | 43 ms | 1400 KB |
1_03.txt | AC | 43 ms | 1400 KB |
1_04.txt | AC | 40 ms | 1400 KB |
1_05.txt | AC | 40 ms | 1400 KB |
1_06.txt | AC | 41 ms | 1656 KB |
1_07.txt | AC | 42 ms | 1524 KB |