2023牛客多校(一)

Matches

限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述 

Walk Alone has two rows of matches, each of which contains n matches. He defines the distance between them as ∣d=∑i=1n​∣ai​−bi​∣, where ai​ and bi​ represent the height of the i-th match in the first row and the second row, respectively. Walk Alone wants to beautify the matches by shortening the distance, and you are asked to find out the minimum distance after performing at most one swap within one row. Note that the height can be negative.

输入描述:

The first line contains one integer  (1≤n≤106) (1≤n≤106), denoting the number of matches in each row.

The second and the third line both contains n integers, representing the height of matches in the first row and the second row, respectively. All of these numbers satisfy ∣≤109∣ai​∣,∣bi​∣≤109.

输出描述:

Print one line containing a single integer, the minimum distance you can get.

#include
#include
#include


using namespace std;
const long long N=1e6+5;
struct node
{
    int  x,y;
    int xy;
    friend bool operator<(node n1,node n2)
    {
        return n1.xy>n2.xy;
    }
}e[N];

signed main()
{
   ios::sync_with_stdio(false);
    cin.tie(0);
   // cout.tie(0);
    long long n;
    cin>>n;
    long long ans=0,tep=0;//注意要用long long
    for(long long i=1;i<=n;i++)
    {
        cin>>e[i].x;
        //scanf("%lld",&e[i].x);
    }
    for(long long i=1;i<=n;i++)
    {
        cin>>e[i].y;
         //scanf("%lld",&e[i].y);
        e[i].xy=abs(e[i].x-e[i].y);
        ans+=e[i].xy;
    }
    sort(e+1,e+1+n);
    tep=ans;
    long long ct=0;
    for(int i=1;i<=n/2+1;i++)
    
    { //  cout<<"dsk: "<1e7)break;
        }
        if(ct>1e7)break;
    }
    cout<

你可能感兴趣的:(acm2023夏训,算法)