やるだけ
class ContiguousCacheEasy { public: int bytesRead(int n, int k, vector <int> adr) { int ret = 0; int mn = 0; int mx = k - 1; for (int i = 0; i < (int)adr.size(); ++i) { if (mn <= adr[i] && adr[i] <= mx) { } else { int mn_ = mn; int mx_ = mx; while (mx < adr[i]) { ++mn; mx = mn + (k - 1); } while (adr[i] < mn) { --mn; mx = mn + (k - 1); } if (false) { } else if (mn_ <= mn && mn <= mx_) { ret += (mx - mn_) - (k - 1); } else if (mn_ <= mx && mx <= mx_) { ret += (mx_ - mn) - (k - 1); } else { ret += k; } } } return ret; } };