# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
570673 | 2022-05-31T03:54:02 Z | AGE | Simfonija (COCI19_simfonija) | C++14 | 310 ms | 4464 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>=0;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=0;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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 115 ms | 296 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 256 ms | 2960 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 291 ms | 2892 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 262 ms | 2908 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 163 ms | 1872 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 306 ms | 4444 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 200 ms | 2468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 310 ms | 4464 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 278 ms | 2600 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 223 ms | 2484 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |