UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206972#3728. 线性回归Allen123456hello1001ms1312kbC++11983b2024-07-26 18:15:132024-07-26 21:46:43

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct nd{
    LL x,y;int id;
    bool operator<(const nd& a) const{
        return (x-y)*(x-y)<(a.x-a.y)*(a.x-a.y);
    }
};
priority_queue<nd> apple;
LL arr[1005],brr[1005];
int k1,k2,n;
int main(){
    scanf("%d%d%d",&n,&k1,&k2);
    for (int i=1;i<=n;++i){scanf("%lld",arr+i);}
    for (int i=1;i<=n;++i){scanf("%lld",brr+i);}
    for (int i=1;i<=n;++i){apple.push({arr[i],brr[i],i});}
    nd cur;
    ++k1;while (--k1){
        cur=apple.top();apple.pop();
        if (cur.x>cur.y){--arr[cur.id];}else{++arr[cur.id];}
        apple.push({arr[cur.id],brr[cur.id],cur.id});
    }
    ++k2;while (--k2){
        cur=apple.top();apple.pop();
        if (cur.x>cur.y){++brr[cur.id];}else{--brr[cur.id];}
        apple.push({arr[cur.id],brr[cur.id],cur.id});
    }
    LL ans=0;
    for (int i=1;i<=n;++i){ans+=(arr[i]-brr[i])*(arr[i]-brr[i]);}
    printf("%lld",ans);
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

10 6 2
454418 -21426 23410 -443720 225317 -685090 80034 -728695 -384192 416885
-941014 437793 -21070...

output:

5158776212426

result:

ok 1 number(s): "5158776212426"

Test #2:

score: 10
Accepted
time: 1ms
memory: 1256kb

input:

7 5 3
-726055 789663 546332 -572937 -114642 -24729 -65539
910769 719028 -762815 971833 -51397 -76057...

output:

7340826837620

result:

ok 1 number(s): "7340826837620"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1276kb

input:

145 0 1
714745 473118 -360070 -879359 -565865 -173780 -906712 715547 259048 40922 -956534 886945 766...

output:

97736494687094

result:

ok 1 number(s): "97736494687094"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

107 1 1
-946535 -89553 156363 113243 -185508 -570695 230514 564782 950532 353178 -462581 753586 -871...

output:

77662625409028

result:

ok 1 number(s): "77662625409028"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1268kb

input:

171 125 74
366955 -483111 -214043 883670 -873452 537606 -892146 185468 -521414 986822 -402553 -12202...

output:

101824656703435

result:

ok 1 number(s): "101824656703435"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

102 130 32
-464430 -307476 -253513 -605233 330089 906266 749185 -663800 570293 -538072 443285 -41426...

output:

74022150616924

result:

ok 1 number(s): "74022150616924"

Test #7:

score: 10
Accepted
time: 0ms
memory: 1312kb

input:

880 925 26
-400382 -56034 559256 -36567 -246370 990342 -986983 -941884 932594 -123561 -484678 -90634...

output:

552289715840346

result:

ok 1 number(s): "552289715840346"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1312kb

input:

953 822 20
-420214 344903 -285687 -480800 921852 -24628 100883 -318341 849126 -554604 -476435 580574...

output:

598734857665984

result:

ok 1 number(s): "598734857665984"

Test #9:

score: 10
Accepted
time: 0ms
memory: 1304kb

input:

621 636 288
636387 -78786 410613 -27662 -656072 113546 -135323 -842935 -370862 383957 278465 -45638 ...

output:

433452844975546

result:

ok 1 number(s): "433452844975546"

Test #10:

score: 10
Accepted
time: 0ms
memory: 1308kb

input:

800 616 256
20476 987852 -955837 159323 -250711 -762835 260050 499413 -40854 471982 809493 463149 16...

output:

552952018857639

result:

ok 1 number(s): "552952018857639"