?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
188155033 |
Practice: DaiRuiChen007 |
1674E - 212 | C++14 (GCC 6-32) | Accepted | 62 ms | 796 KB | 2023-01-06 04:59:24 | 2023-01-06 04:59:24 |
// LUOGU_RID: 98796908 #include<bits/stdc++.h> using namespace std; const int MAXN=2e5+1,INF=1e9; int n,a[MAXN]; inline int cost1() { //a[i] and a[i+1] int ret=INF; for(int i=1;i<n;++i) { if(max(a[i],a[i+1])>=2*min(a[i],a[i+1])) ret=min(ret,(max(a[i],a[i+1])+1)/2); else ret=min(ret,(a[i]+a[i+1]+2)/3); } return ret; } inline int cost2() { //a[i-1] and a[i+1] int ret=INF; for(int i=2;i<n;++i) { ret=min(ret,(a[i-1]+a[i+1]+1)/2); } return ret; } inline int cost3() { //a[x] and a[y], |x-y|>2 int fir=INF,sec=INF; for(int i=1;i<=n;++i) { if(a[i]<fir) sec=fir,fir=a[i]; else if(a[i]<sec) sec=a[i]; } return (fir+1)/2+(sec+1)/2; } signed main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); printf("%d\n",min(min(cost1(),cost2()),cost3())); return 0; }
?
?
?
?