Submission #570674

# Submission time Handle Problem Language Result Execution time Memory
570674 2022-05-31T03:55:30 Z AGE Simfonija (COCI19_simfonija) C++14
0 / 110
337 ms 3172 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
const int N=1e6,M=2e3;

int a[100005],b[100005];
main()
{

    int n,m;
    cin>>n>>m;

    map<int,int>mp;

    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
        cin>>b[i];

    for(int i=0;i<n;i++)
        mp[a[i]-b[i]]++;

    int neg=0,pos=0;
    for(auto x:mp){

        if(x.F<0)
            neg+=x.S;

        else pos+=x.S;

    }

    int ans=0,anss=1e18;

    for(int i=0;i<n;i++)
        ans+=abs(a[i]-b[i]);

    anss=min(abs(ans),anss);

    for(int j=-2e6;j>=1;j--){

        ans-=pos;
        ans+=neg;

        anss=min(anss,abs(ans));
        neg+=mp[-j];
        pos-=mp[-j];
        
        if(mp[-j]==0)
            mp.erase(-j);
    }

    ans=0,pos=0,neg=0;

    for(int i=0;i<n;i++)
        ans+=abs(a[i]-b[i]);

    for(auto x:mp)
        if(x.F<0)
            neg+=x.S;

        else pos+=x.S;

    for(int j=1;j<=2e6;j++){

        ans-=neg;
        ans+=pos;

        anss=min(anss,abs(ans));
        neg-=mp[-j];
        pos+=mp[-j];
        
        if(mp[-j]==0)
            mp.erase(-j);
    }

    cout<<anss<<endl;
    return 0;
}

Compilation message

simfonija.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~
simfonija.cpp: In function 'int main()':
simfonija.cpp:36:20: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   36 |     int ans=0,anss=1e18;
      |                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 125 ms 292 KB Output is correct
2 Correct 117 ms 212 KB Output is correct
3 Incorrect 123 ms 304 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 287 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 282 ms 1540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 272 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 337 ms 3172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 322 ms 3048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 270 ms 1304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 218 ms 1072 KB Output isn't correct
2 Halted 0 ms 0 KB -