90pts WAon#9

P1029 [NOIP2001 普及组] 最大公约数和最小公倍数问题

001_zip @ 2024-12-10 19:48:57

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long a[20001],b[20001],l=0;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    sort(a,a+n);
    sort(b,b+n);
    for(int i=0;i<n;i++){
        l+=b[i]-a[i];
        if(i+1<n) if(b[i]>a[i+1])l-=b[i]-a[i+1];
    }
    cout<<l;
}

by 4041nofoundGeoge @ 2024-12-10 19:52:58

@001_zip你是不是发错题了


by weihaisunyingjie @ 2024-12-20 14:28:12

@4041nofoundGeoge yes


by 001_zip @ 2024-12-21 14:05:11

是的


|