Submission #3600798
Source Code Expand
#include<iostream> #include<utility> #include<algorithm> #include<vector> #define all(v) v.begin(),v.end() #define pb push_back #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define INF 1e9 using namespace std; typedef pair<long long,int> pli; long long func(long long a){ if(a<0)return -a; else return a; } long long min(long long a,long long b){ if(a<b)return a; else return b; } int main(){ int n,k; cin>>n>>k; long long val[n]; rep(i,n)cin>>val[i]; long long ans=INF; rep(i,n-k+1){ if(val[i]>=0)ans=min(ans,val[i+k-1]); else if(val[i+k-1]<0)ans=min(ans,func(val[i])); else{ ans=min(ans,min(func(val[i])*2+func(val[i+k-1]),func(val[i])+2*func(val[i+k-1]))); } } cout<<ans<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Candles |
User | tuki_remon |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 781 Byte |
Status | AC |
Exec Time | 42 ms |
Memory | 1024 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 | 39 ms | 1024 KB |
1_01.txt | AC | 39 ms | 1024 KB |
1_02.txt | AC | 41 ms | 1024 KB |
1_03.txt | AC | 42 ms | 1024 KB |
1_04.txt | AC | 37 ms | 1024 KB |
1_05.txt | AC | 37 ms | 1024 KB |
1_06.txt | AC | 38 ms | 1024 KB |
1_07.txt | AC | 39 ms | 1024 KB |