cf-12B Correct Solution[水] 660C Hard Process[尺取法]

12B-Correct Solution

Description

One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice’s turn, she told the number n to Bob and said:

—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.

—No problem! — said Bob and immediately gave her an answer.

Alice said a random number, so she doesn’t know whether Bob’s answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.

Input

The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob’s answer, possibly with leading zeroes.

Output

Print OK if Bob’s answer is correct and WRONG_ANSWER otherwise.

Sample Input 
Input

3310 
1033

Output

OK

Input


5

Output

WRONG_ANSWER 
sort一下之后直接找第一个0和第一个非0就OK了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
char a[10010];
char b[10010], c[1010], d[1010];
int main() {
    while (scanf("%s%s", a, b) != EOF) {
            int len = strlen(a);
    sort(a, a + len);
    int flag = 0;
    for (int i = 0; i < len; i++) {
            if (a[i] != '0') {
                flag = i;
    char t = a[i];
    a[i] = a[0];
    a[0] = t;
    break;
    }
    }
    if (strcmp(a, b) == 0) {
            printf("OK\n");
    }
    else
        {
            printf("WRONG_ANSWER\n");
            }
}
return 0;
}
 660C Hard Process

You are given an array a with n elements. Each element of a is either 0 or 1.

Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).

Input

The first line contains two integers n and k (1 ≤ n ≤ 3·105, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.

The second line contains n integers ai (0 ≤ ai ≤ 1) — the elements of a.

Output

On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.

On the second line print n integers aj — the elements of the array a after the changes.

If there are multiple answers, you can print any one of them.

Example
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
#include<iostream>
#include<cstdio> 
#include<cstdlib>
#include<cstring>
#include<algorithm> 
using namespace std;
const int maxn=300005;
int n,k;
int a[maxn],sum[maxn]={0};
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){//10010  01223  5 1
						 // 01101  01223  mid=3
		cin>>a[i];
		
		if(a[i]==1){
			sum[i]=sum[i-1];
//			ans=max(ans,sum[i]);
		}
		else{
			sum[i]=sum[i-1]+1;
		}
		a[i]=1-a[i];
	}
//	for(int i=1;i<=n;i++){
//		sum[i]=sum[i-1]+a[i];
//	}
	int ans=0,res=0;
	for(int i=1;i<=n;i++){
		int L=i,R=n;
		int temp=0;
		while(L<=R){
			int mid=(L+R)/2;
			if(sum[mid]-sum[i-1]-1>k-1){
				R=mid-1;
			}
			else{
				L=mid+1;
				temp=mid-i+1;
			}
		} 
		if(temp>ans){
			ans=temp;
			res=i;
		//	cout<<"ans="<<ans<<"  "<<"res="<<res<<endl;
		}
	}
	cout<<ans<<endl;
	for(int i=res;i<=n;i++){
		if(!ans) break;
		if(a[i]==1) a[i]=0;
		if(!a[i]) ans--;
		//cout<<"ans--="<<ans<<endl;//10010  01101 00101
	}
	for(int i=1;i<=n;i++){
		cout<<1-a[i]<<" ";
	}
	cout<<endl;
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值