Codeforces Global Round 2

A

 

 

题解: 枚举每个颜色的头和尾然后最大化另一端

upd:赛时麻烦了,显然答案的一端为头或者尾,枚举另一端即可。

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int N=1e6+3;
ll n,a[N];
set<ll>q[N];
void Solve()
{
    cin>>n;ll s=0;
    for(int i=1;i<=n;i++)q[i].clear();
    for(int i=1;i<=n;i++)cin>>a[i],q[a[i]].insert(i);
    for(int i=1;i<=n;i++)
    {
        if(q[i].empty())continue;
        ll x=*q[i].begin(),y=*q[i].rbegin(),px=n,py=1;
        while(q[i].count(px))px--;
        while(q[i].count(py))py++;
        s=max(s,max(px-x,y-py));
    }
    cout<<s<<endl;
}
int main()
{
    int T;T=1;
    while(T--)Solve(); 
    return 0;
}
View Code

B

一个大小是 $2 \times h$ 的冰箱(就是 $2$ 列 $h$ 行),有 $n$ 个瓶子,高度分别是$a_i$,我们放 $k$ 个瓶子进入冰箱,

上下两个瓶子之间有挡板,且挡板不能将瓶子分割,求出能满足将前 $k$ 个瓶子放入冰箱的最大的 $k$

posted @ 2023-01-30 21:11  Hanghang007  阅读(25)  评论(2)    收藏  举报