Submission #3080472


Source Code Expand

Copy
#include<iostream>
#include<vector>
using namespace std;

int main(){
	int N,K;
	cin >> N >> K;
	vector< int > X(N);
	
	int x;
	int origin = 0;
	for(int i = 0; i < N; i++)
	{
		cin >> X[i];
		if(i>0 && X[i-1] <0 && X[i] >=0){
			origin = i;
		}
	}	
	
	int l = (origin + K -1) > X.size()-1 ? X.size()-1:(origin + K -1);
	// cout << origin << endl;
	int r = (origin - K) < 0 ? 0 : origin-K;
	int ans = 1e9 + 7;
	// cout << r << endl;
	// cout << l << endl;
	for(int i = l; i-K+1 >= r; i--)
	{
		int right = X[i];
		int left = X[i-K+1];
		// cout << i  << ":" << right<< endl;
		// cout << i-K+1 << ":" << left << endl;
		// cout << "------" << endl;
		if(right>=0 && left<0){
			ans = min(ans, right*2+abs(left));
			ans = min(ans, right+abs(left)*2);
		}else if(right>=0){
			ans = min(ans, right);
		}else{
			ans = min(ans,abs(left));
		}
	}
	cout << ans << endl;
	
	return 0;

}

Submission Info

Submission Time
Task C - Candles
User yusan1871
Language C++14 (GCC 5.4.1)
Score 0
Code Size 929 Byte
Status WA
Exec Time 41 ms
Memory 640 KB

Judge Result

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