Submission #334964

#TimeUsernameProblemLanguageResultExecution timeMemory
334964ronnithSimfonija (COCI19_simfonija)C++14
44 / 110
52 ms3456 KiB
#include <bits/stdc++.h> #define trav(a, b) for(auto a : b) #define mk make_pair #define f first #define s second #define vi vector<int> #define pb push_back typedef long long ll; using namespace std; void re(vector<ll*> arr){ trav(e, arr)scanf("%lld", e); } ll n, k; ll a[100000], b[100000]; ll check(ll x){ ll ans = 0; for(int i = 0;i < n;i ++){ ans += abs(a[i] + x - b[i]); } return ans; } int main(){ // ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); re({&n,&k}); for(int i = 0;i < n;i ++){ re({&a[i]}); } for(int i = 0;i < n;i ++){ re({&b[i]}); } ll hi = 1e13; ll lo = -1e13; ll ans = LONG_LONG_MAX; while(hi >= lo){ ll g1 = lo + (hi - lo) / 2; ll g2 = g1 + 1; ll a1 = check(g1), a2 = check(g2); if(a1 == a2){ ans = a1; break; } else if(a1 < a2){ ans = min(ans, a1); hi = g1 - 1; } else if(a1 > a2){ ans = min(ans, a2); lo = g1 + 1; } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

simfonija.cpp: In function 'void re(std::vector<long long int*>)':
simfonija.cpp:12:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  trav(e, arr)scanf("%lld", e);
      |              ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...