为什么不能用map啊。。。
查看原帖
为什么不能用map啊。。。
373938
wowwowwow楼主2022/7/15 14:13

本蒟蒻突发奇想用map写,结果TLE了...

#include<bits/stdc++.h>
#define int long long
using namespace std;

map<int, int> a; //我的思路是存下每个时间点的优惠劵对应的票价

int n;

signed main(){
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int o, p, t;
		cin >> o >> p >> t;
		if(o == 0){ //地铁时存
			ans += p;
			a[t] = p;
		}
		else{
			int f = 0;
			for(int j = t - 45; j <= t; j++){ //取
				if(a[j] >= p){
					a[j] = -1;
					f = 1;
					break;
				}
			}
			if(!f){
				ans += p;
			}
		}
	}
	cout << ans;
	return 0;
}

求大佬解答

2022/7/15 14:13
加载中...