제출 #455296

#제출 시각아이디문제언어결과실행 시간메모리
455296armandFountain (eJOI20_fountain)C++14
60 / 100
1571 ms2532 KiB
#include <iostream> #include <algorithm> using namespace std; const int N = 100005; int d[N], c[N]; int n, q; long long pref[N]; bool is_increasing() { int i; for (i = 2; i <= n; i++) if (d[i] <= d[i - 1]) return false; return true; } void solve2() { int i; int r, w; pref[1] = c[1]; for (i = 2; i <= n; i++) pref[i] = pref[i - 1] + c[i]; while (q--) { cin >> r >> w; long long* pt = lower_bound(pref, pref + n + 1, w + pref[r - 1]); int res = pt - pref; if (res <= n) cout << res << endl; else cout << 0 << endl; } } int main() { int i; int r, v; cin >> n >> q; for (i = 1; i <= n; i++) cin >> d[i] >> c[i]; if (is_increasing()) { solve2(); // system("pause"); return 0; } while (q--) { cin >> r >> v; if (v <= c[r]) { cout << r << endl; continue; } i = r + 1; v -= c[r]; while (i <= n) { if (d[i] > d[r]) { if (v <= c[i]) { cout << i << endl; break; } else { v -= c[i]; r = i; i++; } } else i++; } if (i > n) cout << 0 << endl; } // system("pause"); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...