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 principle***ishka 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 decrease***y 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 problem***ishka 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 ***axn],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 ***axn],an***axn];
    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;
}