codeforces #Round490div3 A,B,C

A. Mishka and Contest

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mishka started participating in a programming contest. There are nn problems in the contest. Mishka's problem-solving skill is equal to kk.

Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.

Mishka cannot solve a problem with difficulty greater than kk. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 11. Mishka stops when he is unable to solve any problem from any end of the list.

How many problems can Mishka solve?

Input

The first line of input contains two integers nn and kk (1≤n,k≤1001≤n,k≤100) — the number of problems in the contest and Mishka's problem-solving skill.

The second line of input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai is the difficulty of the ii-th problem. The problems are given in order from the leftmost to the rightmost in the list.

Output

Print one integer — the maximum number of problems Mishka can solve.

#include <iostream>
using namespace std;
int main()
{
    int n,k;
    int p[101];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>p[i];
    int r=n-1,l=0,ans=0;
    while(l<=r)
    {
        if(p[l]<=k) 
        {
            ans++;
            l++;
        }
        else if(p[r]<=k)    {
            ans++;
            r--;
        }
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

B. Reversing Encryption

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A string ss of length nn can be encrypted by the following algorithm:

  • iterate over all divisors of nn in decreasing order (i.e. from nn to 11),
  • for each divisor dd, reverse the substring s[1…d]s[1…d] (i.e. the substring which starts at position 11 and ends at position dd).

For example, the above algorithm applied to the string ss="codeforces" leads to the following changes: "codeforces" →→"secrofedoc" →→ "orcesfedoc" →→ "rocesfedoc" →→ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because d=1d=1).

You are given the encrypted string tt. Your task is to decrypt this string, i.e., to find a string ss such that the above algorithm results in string tt. It can be proven that this string ss always exists and is unique.

Input

The first line of input consists of a single integer nn (1≤n≤1001≤n≤100) — the length of the string tt. The second line of input consists of the string tt. The length of tt is nn, and it consists only of lowercase Latin letters.

Output

Print a string ss such that the above algorithm results in tt.

暴力——————————

#include <bits/stdc++.h>
using namespace std;
const int maxn=101;
int main()
{
    int n,j=0,p[maxn],len;
    char s[maxn],c;
    cin>>n;
    memset(p,0,sizeof(p));
    for(int i=1;i<=n;i++)
        if(n%i==0)
        {
            p[j]=i;
            j++;
        }
    for(int i=0;i<n;i++)
        if(p[i]==0)
        {
            len=i+1;
            break;
        }
    scanf("%s",s);
    if(strlen(s)==1)
    {
        printf("%s\n",s);
        return 0;
    }
    if(strlen(s)==2)
    {
        c=s[0];
        s[0]=s[n-1],s[n-1]=c;
        printf("%s\n",s);
        return 0;
    }
    for(int i=0;i<len;i++)
    {
        for(int k=0;k<p[i]/2;k++)
        {
            c=s[k];
            s[k]=s[p[i]-k-1],s[p[i]-k-1]=c;
        }
    }
    printf("%s\n",s);
    return 0;
}

C. Alphabetic Removals

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly kk characters (k≤nk≤n) from the string ss. Polycarp uses the following algorithm kk times:

  • if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
  • if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;
  • ...
  • remove the leftmost occurrence of the letter 'z' and stop the algorithm.

This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly kk times, thus removing exactly kk characters.

Help Polycarp find the resulting string.

Input

The first line of input contains two integers nn and kk (1≤k≤n≤4⋅1051≤k≤n≤4⋅105) — the length of the string and the number of letters Polycarp will remove.

The second line contains the string ss consisting of nn lowercase Latin letters.

Output

Print the string that will be obtained from ss after Polycarp removes exactly kk letters using the above algorithm kk times.

If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).

#include <bits/stdc++.h>
using namespace std;
const int maxn=4e5+5;
int main()
{
    char s[maxn],ans[maxn];
    int n,k,a[30],flag,rest,sum,len=0;
    cin>>n>>k;
    scanf("%s",s);
    for(int i=0;i<n;i++) a[s[i]-'a']++;
    for(int i=0;i<26;i++)
    {
        sum+=a[i];
        if(sum>=k)
        {
            flag=i;
            rest=a[i]-sum+k;
            break;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(s[i]-'a'>flag)
            ans[len++]=s[i];
        else if(s[i]-'a'==flag)
        {
            rest--;
            if(rest<0)
                ans[len++]=s[i];
        }
    }
    printf("%s\n",ans);
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值