Codeforces Round #243 (Div. 2)

又要掉分了。。。

A. Sereja and Mugs

Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.

As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (n - 1) friends. Determine if Sereja's friends can play the game so that nobody loses.

Input

The first line contains integers n and s (2 ≤ n ≤ 100; 1 ≤ s ≤ 1000) — the number of mugs and the volume of the cup. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 10). Number ai means the volume of the i-th mug.

Output

In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.

Sample test(s)
Input
3 4
1 1 1
Output
YES
Input
3 4
3 1 3
Output
YES
Input
3 4
4 4 4
Output
NO

思路:去掉最大的然后看he是不是小于等于容积

#include<iostream>
using namespace std;
int main()
{
    int n,s,a,sum=0;
    int max1=-1;
    cin>>n>>s;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        sum+=a;
        if(a>max1)max1=a;
    }
    if(sum-max1<=s)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

B. Sereja and Mirroring

Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:

  • the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;
  • the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1).

Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain?

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.

Output

In the single line, print the answer to the problem — the minimum number of rows of matrix b.

Sample test(s)
Input
4 3
0 0 1
1 1 0
1 1 0
0 0 1
Output
2
Input
3 3
0 0 0
0 0 0
0 0 0
Output
3
Input
8 1
0
1
1
0
0
1
1
0
Output
2
如果行数是奇数则使整个矩阵,然后每次折半,看能不能匹配

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=110;
int n,m;
int a[maxn][maxn];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)cin>>a[i][j];
    if(n%2){cout<<n<<endl;return 0;}
    int ans=0;
    bool f=false,flag;
    while(true)
    {
        int p=n/2;
        int tmp=p;
        flag=true;
        for(int i=1;i<=tmp;i++)
        {
            for(int j=1;j<=m;j++)
                if(a[i][j]!=a[2*p-i+1][j]){flag=false;break;}
        }
        if(p%2&&!flag){ans=p*2;break;}
        if(p%2){ans=p;break;}
        if(flag)n=p;
        else {ans=2*p;break;}
    }
    cout<<ans<<endl;
    return 0;
}

C. Sereja and Swaps

As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:

A swap operation is the following sequence of actions:

  • choose two indexes i, j (i ≠ j);
  • perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.

What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?

Input

The first line contains two integers n and k (1 ≤ n ≤ 200; 1 ≤ k ≤ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 ≤ a[i] ≤ 1000).

Output

In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.

Sample test(s)
Input
10 2
10 -1 2 2 2 2 2 2 -1 10
Output
32
Input
5 10
-1 -1 -1 -1 -1
Output
-1

题意 : 给了两个公式能够求出m(a),然后允许最多交换k次,求其中的最大的m(a)。

思路 : 两个for循环先枚举(l,r)区间能够得到的最大值,并且把这些数存到容器里。然后肯定还有(1,l-1)和(r+1,n)这里边还有数,把这些数存到容器里,然后枚举交换次数,从第二个容器里找出最大值看是否比第一个容器的最小值大,那就交换。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=210;
const int INF=1000000000;
int n,cnt;
int a[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&cnt);
    int sum,ans=-INF;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            vector<int> x,y;
            sum=0;
            for(int k=i;k<=j;k++){x.push_back(a[k]);sum+=a[k];}
            ans=max(ans,sum);
            for(int k=1;k<=n;k++)
            {
                if(k<i||k>j)
                y.push_back(a[k]);
            }
            sort(x.begin(),x.end());
            sort(y.begin(),y.end(),greater<int>());
            for(int k=1;k<=cnt&&k<=x.size()&&k<=y.size();k++)
            {
                if(x[k-1]<y[k-1])
                {
                    sum-=x[k-1];
                    sum+=y[k-1];
                    ans=max(ans,sum);
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值