Submission #714361

#TimeUsernameProblemLanguageResultExecution timeMemory
714361pashkaPotatoes and fertilizers (LMIO19_bulves)C++14
0 / 100
1087 ms852 KiB
#include <bits/stdc++.h> #define long long long int #define DEBUG using namespace std; // @author: pashka int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; int M = 30001; vector<int> d(2 * M, INT_MAX); d[M] = 0; for (int i = 0; i < n; i++) { vector<int> dd(2 * M, INT_MAX); for (int j = 0; j < 2 * M; j++) { if (d[j] == INT_MAX) continue; // cout << i << " " << j << " " << d[j] << "\n"; int x = a[i] - b[i]; if ((j - M) < 0) { int y = x + (j - M); dd[y + M] = min(dd[y + M], d[j] + abs(j - M)); } else { for (int k = 0; k <= (j - M); k++) { int y = x + k; dd[y + M] = min(dd[y + M], d[j] + k); } } } d = dd; } int res = INT_MAX; for (int i = M; i < d.size(); i++) { res = min(res, d[i]); } cout << res << "\n"; return 0; }

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = M; i < d.size(); i++) {
      |                     ~~^~~~~~~~~~
#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...