题意n 位同学按到达时间排队,给出开始打饭时间,等不到就输出 -1。
思路
维护「当前打饭窗口空闲的时刻」free。start = max(free, a[i]);若 start > a[i]+b[i] 则该同学离开,输出 -1 且 free 不变。否则输出 start 并令 free = start + t[i]。
复杂度O(n)。
参考代码(C++)
C++:
#include <cstdio>
int main() {
int n;
if (scanf("%d", &n) != 1) return 0;
long long fre...