Codeforces Round #249 (Div. 2) ABC

A. Queue on Bus Stop
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.

The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.

Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ m).

Output

Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.

Sample test(s)
input
4 3
2 3 2 1
output
3
input
3 4
1 2 1
output
1
#include <cstdio>
#include <iostream>
using namespace std;
int n,m;
int a[110];
int main()
{
    cin>>n>>m;
    int t;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=1;
    int cur=m;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=cur)
            cur-=a[i];
        else ans+=1,cur=m-a[i];
    }
    cout<<ans<<endl;
    return 0;
}
B. Pasha Maximizes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.

Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

Input

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Output

Print the maximum number that Pasha can get if he makes at most k swaps.

Sample test(s)
input
1990 1
output
9190
input
300 0
output
300
input
1034 2
output
3104
input
9090000078001234 6
output
9907000008001234

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char s[30];
int k;
int main()
{
    scanf("%s %d",s,&k);
    if(k==0)
    {
        cout<<s<<endl;
        return 0;
    }

    int cur=k;
    int len=strlen(s);
    if(len==1)
    {
        cout<<s<<endl;
        return 0;
    }
    for(int i=0;i<len;i++)
    {
        if(cur==0) break;
        int index=-1;
        char maxx=s[i];
        for(int j=1;j<=cur&&i+j<=len;j++)
        {
            if(s[i]<s[i+j]&&maxx<s[i+j]) maxx=s[i+j] ,index=j;
        }
        if(index==-1) continue;
        cur-=index;
        char t=s[i+index];

        for(int j=index;j>=1;j--)
        {
            s[i+j]=s[i+j-1];
        }
        s[i]=t;
    }
    cout<<s<<endl;
    return 0;
}

C. Cardiogram
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In this problem, your task is to use ASCII graphics to paint a cardiogram.

A cardiogram is a polyline with the following corners:

That is, a cardiogram is fully defined by a sequence of positive integers a1, a2, ..., an.

Your task is to paint a cardiogram by given sequence ai.

Input

The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.

Output

Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print  characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram.

Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty.

Sample test(s)
input
5
3 1 2 5 1
output
      / \     
   / \ /   \    
  /       \   
 /         \  
          \ / 
input
3
1 5 1
output
 / \     
  \    
   \   
    \  
     \ / 
Note

Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below.

http://assets.codeforces.com/rounds/435/1.txt

http://assets.codeforces.com/rounds/435/2.txt


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;
char g[2000][1010];
int n;
int main()
{
    for(int i=0;i<2000;i++)
        for(int j=0;j<1010;j++)
        g[i][j]=' ';
    cin>>n;
    int now=1000;
    int cur=0;
    int minn=2000;
    int maxx=0;
    for(int i=0;i<n;i++)
    {
        int t;
        cin >>t;
        if(i%2==0)//odd
        {
            for(int j=0;j<t;j++)
            {
                maxx=max(maxx,now);
                minn=min(minn,now);
                g[now--][cur++]='/';
            }
            now++;
        }
        else//even
        {
            for(int j=0;j<t;j++)
            {
                maxx=max(maxx,now);
                minn=min(minn,now);
                g[now++][cur++]='\\';
            }
            now--;
        }
    }
    for(int i=minn;i<=maxx;i++)
        g[i][cur]='\0';
    for(int i=minn;i<=maxx;i++)
        puts(g[i]);
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值