Submission #725468

#TimeUsernameProblemLanguageResultExecution timeMemory
725468bufferingExhibition (JOI19_ho_t2)C++17
100 / 100
71 ms5436 KiB
#include <bits/stdc++.h> using namespace std; void IO(string s = "") { if (s == "") { freopen("input.txt", "r", stdin); freopen("output 2.txt", "w", stdout); } if (s != "") { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } bool check(int k, vector<pair<int, int>>& p, vector<int>& frames) { vector<int> sizes; for (int i = frames.size() - k; i < frames.size(); i++) { sizes.push_back(frames[i]); } bool works = true; int pointer = 0; for (int i = 0; i < k; i++) { bool curr = false; for (int j = pointer; j < p.size(); j++) { if (p[j].second <= sizes[i]) { pointer = j + 1; curr = true; break; } } works &= curr; if (!works) break; if (pointer >= p.size() && i != k - 1) { works = false; break; } } return works; } int main() { ios::sync_with_stdio(false); cin.tie(0); //IO(); /* Binary search for answer If x is k, choose suffix of sizes for frames For each i in suffix, choose frame with size <= i with least value */ int n; int m; cin >> n >> m; vector<pair<int, int>> p(n); vector<int> frames(m); for (int i = 0; i < n; i++) { cin >> p[i].second >> p[i].first; //{value, size} } for (int i = 0; i < m; i++) { cin >> frames[i]; } sort(p.begin(), p.end()); sort(frames.begin(), frames.end()); int lo = 0; int hi = min(n, m); while (lo <= hi) { int mid = (lo + hi)/2; if (check(mid, p, frames)) { if (mid == min(n, m) || !check(mid + 1, p, frames)) { cout << mid << endl; return 0; } else lo = mid + 1; } else hi = mid - 1; } }

Compilation message (stderr)

joi2019_ho_t2.cpp: In function 'bool check(int, std::vector<std::pair<int, int> >&, std::vector<int>&)':
joi2019_ho_t2.cpp:19:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = frames.size() - k; i < frames.size(); i++) {
      |                                     ~~^~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:25:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int j = pointer; j < p.size(); j++) {
      |                               ~~^~~~~~~~~~
joi2019_ho_t2.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         if (pointer >= p.size() && i != k - 1) {
      |             ~~~~~~~~^~~~~~~~~~~
joi2019_ho_t2.cpp: In function 'void IO(std::string)':
joi2019_ho_t2.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("output 2.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...