Submission #792484

#TimeUsernameProblemLanguageResultExecution timeMemory
792484vjudge1Bitaro's travel (JOI23_travel)C++17
15 / 100
3045 ms3028 KiB
#ifdef Home #define _GLIBCXX_DEBUG #endif // Home #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; main() { #ifdef Home freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // Home ios_base::sync_with_stdio(0); cin.tie(0); ll n, q, x, ans, l, r; cin >> n; vector < int > a(n); for(auto &i : a) { cin >> i; } for(cin >> q; q --> 0;) { cin >> x; r = upper_bound(a.begin(), a.end(), x) - a.begin(), l = r - 1; ans = 0; for(int t = n; t --> 0;) { if(l < 0) { ans += a[r] - x; x = a[r]; ++ r; } else if(r == n) { ans += x - a[l]; x = a[l]; -- l; } else { if(x - a[l] <= a[r] - x) { ans += x - a[l]; x = a[l]; -- l; } else { ans += a[r] - x; x = a[r]; ++ r; } } } cout << ans << '\n'; } }

Compilation message (stderr)

travel.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...