Submission #394451

#TimeUsernameProblemLanguageResultExecution timeMemory
394451iulia13Bitwise (BOI06_bitwise)C++14
100 / 100
1 ms324 KiB
#include <iostream> using namespace std; struct ura{ int x, y; }; ura v[105]; int l[105]; int scad[105]; ///2^j +.... int main() { int n, i, j, b, p, sol = 0; cin >> n >> p; for (i = 1; i <= p; i++) { cin >> l[i]; l[i] += l[i - 1]; } for (i = 1; i <= n; i++) cin >> v[i].x >> v[i].y; for (i = 30; i >= 0; i--) { int ok = 1; int put = (1 << i); for (b = 1; b <= p && ok; b++) { scad[b] = 0; ok = 0; for (j = l[b - 1] + 1; j <= l[b]; j++) { if (v[j].y >= put && (!scad[b] || v[j].x >= put)) { ok = 1; scad[b] = j; } } } if (ok) { sol += put; for (b = 1; b <= p; b++) v[scad[b]].x = max(v[scad[b]].x, put); } for (j = 1; j <= n; j++) if (v[j].x >= put) { v[j].x -= put; v[j].y -= put; } } cout << sol; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...