Codeforces Round #446 (Div. 2)

A. Greed
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi(ai  ≤  bi).

Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!

Input

The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans.

The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans.

The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans.

Output

Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).

You can print each letter in any case (upper or lower).

Examples
input
2
3 5
3 6
output
YES
input
3
6 8 9
6 10 12
output
NO
input
5
0 0 5 0 0
1 1 8 10 5
output
YES
input
4
4 1 0 3
5 2 2 3
output
YES
Note

In the first sample, there are already 2 cans, so the answer is "YES".

 

n个数据的和,然后在另一个n个数取两个大就行了,我不小心爆了LL

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    long long s=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        s+=x;
        if(s>int(2e9)){printf("NO");return 0;}
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
        sort(a+1,a+n+1);
    printf("%s",(s<=a[n]+a[n-1])?"YES":"NO");
    return 0;
}
B. Wrath
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Hands that shed innocent blood!

There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.

You are given lengths of the claws. You need to find the total number of alive people after the bell rings.

Input

The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people.

Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.

Output

Print one integer — the total number of alive people after the bell rings.

Examples
input
4
0 1 0 10
output
1
input
2
0 0
output
2
input
10
1 1 3 0 0 0 2 1 0 3
output
3
Note

In first sample the last person kills everyone in front of him.

 

 直接暴力下取大

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
ll l[N],ma[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    memset(ma,0,sizeof(ma));
    for(ll i=1;i<=n;i++){
        cin>>l[i];
        ll x=max(1LL,i-l[i]);
        ma[x]=max(i-x,ma[x]);
    }
    ll ans=0,f=0;
    for(ll i=1;i<=n;i++){
        f=max(f,ma[i]);
        if(f==0)ans++;
        f--;
    }
    cout<<ans;
    return 0;
}
C. Pride
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacentelements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the greatest common divisor.

What is the minimum number of operations you need to make all of the elements equal to 1?

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements in the array.

The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Output

Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.

Examples
input
5
2 2 3 4 6
output
5
input
4
2 4 6 8
output
-1
input
3
2 6 9
output
4
Note

In the first sample you can turn all numbers to 1 using the following 5 moves:

  • [2, 2, 3, 4, 6].
  • [2, 1, 3, 4, 6]
  • [2, 1, 3, 1, 6]
  • [2, 1, 1, 1, 6]
  • [1, 1, 1, 1, 6]
  • [1, 1, 1, 1, 1]

We can prove that in this case it is not possible to make all numbers one using less than 5 moves.

这个有1的话就得直接输出啊,n-f

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int a[N],b[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int f=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]==1)f++;
    }
    if(f)printf("%d",n-f);
    else
    {
        f=1;
        for(;;)
        {
            if(f>888*n)
            {
                printf("-1");
                return 0;
            }
            for(int i=f+1; i<=n; i++)
            {
                b[i]=__gcd(a[i-1],a[i]);
                if(b[i]==1)
                {
                    cout<<f+n-1;
                    return 0;
                }
            }
            f++;
            for(int i=1; i<=n; i++)a[i]=b[i];
        }
    }
    return 0;
}
D. Gluttony
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n0 < k < n) the sums of elements on that positions in aand b are different, i. e.

Input

The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.

The second line contains n space-separated distinct integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the elements of the array.

Output

If there is no such array b, print -1.

Otherwise in the only line print n space-separated integers b1, b2, ..., bn. Note that b must be a permutation of a.

If there are multiple answers, print any of them.

Examples
input
2
1 2
output
2 1 
input
4
1000 100 10 1
output
100 1 1000 10
Note

An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.

Note that the empty subset and the subset containing all indices are not counted.

 

 这个P金爷讲思路,跟着做就行了

#include<bits/stdc++.h>
using namespace std;
const int N=200;
pair<int,int>a[N];
int ans[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&a[i].first),a[i].second=i;
    sort(a,a+n);
    for(int i=0; i<n; i++)
    {
        int to=a[i].second;
        if(i==0)
            ans[to]=a[n-1].first;
        else
            ans[to]=a[i-1].first;
    }
    for(int i=0; i<n; i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}

 

 

 

转载于:https://www.cnblogs.com/BobHuang/p/7858250.html

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值