Submission #376052

#TimeUsernameProblemLanguageResultExecution timeMemory
376052MilosMilutinovicBoxes with souvenirs (IOI15_boxes)C++14
Compilation error
0 ms0 KiB
/** * author: milos * created: 10.03.2021 17:16:12 **/ #include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int n, int k, int l, int* a) { sort(a, a + n); vector<long long> pref(n, 0LL); for (int i = 0; i < n; i++) { if (i > 0) { pref[i] = pref[i - 1]; } if (i % k != 0) { pref[i] -= a[i - 1] * 2; } pref[i] += a[i] * 2; } vector<long long> suff(n, 0LL); for (int i = n - 1; i >= 0; i--) { if (i < n - 1) { suff[i] = suff[i + 1]; } if ((n - i - 1) % k != 0) { suff[i] -= (l - a[i + 1]) * 2; } suff[i] += (l - a[i]) * 2; } for (int i = 0; i < n; i++) { cout << pref[i] << " "; } /*cout << '\n'; for (int i = 0; i < n; i++) { cout << suff[i] << " "; } cout << '\n'; long long ans = suff[0]; for (int i = 0; i < n; i++) { ans = min(ans, pref[i] + (i < n - 1 ? suff[i + 1] : 0LL)); }*/ if (k == n) { ans = min(ans, (long long) l); } else { //ans = min(ans, (long long) l + suff[k]); } for (int i = 0; i < n; i++) { ans = min(ans, pref[i] + (i < n - k - 1 ? suff[i + k + 1] : 0LL) + l); } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:45:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   45 |     ans = min(ans, (long long) l);
      |     ^~~
      |     abs
boxes.cpp:50:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   50 |     ans = min(ans, pref[i] + (i < n - k - 1 ? suff[i + k + 1] : 0LL) + l);
      |     ^~~
      |     abs
boxes.cpp:52:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |   return ans;
      |          ^~~
      |          abs