1 条题解
-
0
C++ :
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010; int n; //优惠券 struct Ticket { int time, price; bool used; } tk[N]; int main() { scanf("%d", &n); // 表示总记录数量 int res = 0; // 总花费 for (int i = 0, l = 0, r = 0; i < n; i++) { int type, price, time; scanf("%d%d%d", &type, &price, &time); if (type == 0) { res += price; tk[r++] = {time, price}; } else { while (l < r && time - tk[l].time > 45) l++; //弹出不在窗口内的所有优惠券 bool success = false; for (int i = l; i < r; i++) if (tk[i].used == false && tk[i].price >= price) { tk[i].used = true; //表示优惠券被用过了,防止重复使用 success = true; break; } if (!success) res += price; } } printf("%d\n", res); return 0; }
- 1
信息
- ID
- 3816
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者