G: Collecting Balls I

问题 G: Collecting Balls I
时间限制: 1 Sec 内存限制: 128 MB
提交: 339 解决: 228
[提交] [状态] [讨论版] [命题人:admin]
题目描述

There are N balls in the xy-plane. The coordinates of the i-th of them is (xi,i). Thus, we have one ball on each of the N lines y=1, y=2, …, y=N.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0,i), and the i-th type-B robot at coordinates (K,i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y=1, y=2, …, y=N.
When activated, each type of robot will operate as follows.
When a type-A robot is activated at coordinates (0,a), it will move to the position of the ball on the line y=a, collect the ball, move back to its original position (0,a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
When a type-B robot is activated at coordinates (K,b), it will move to the position of the ball on the line y=b, collect the ball, move back to its original position (K,b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Constraints
1≤N≤100
1≤K≤100
0

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int x;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        int Min=min((k-x),x);
        sum+=Min*2;
    }
    cout<<sum;
    return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值