有大佬帮我看下代码,为什么过不了吗,哭辽,我感觉没问题的呀。谢谢
#include <iostream> #include <vector> #include <map> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m;//n个人,m个角色 vector<int> arr1(n); for (int i = 0; i < n; i++) cin >> arr1[i];//每个人期待的戏份 map<int,int> arr2; int x; for (int i = 0; i < m; i++) { cin >> x;//剩余的戏份 arr2[x]=i+1; } vector<int> ans(n,-1); for (int i = 0; i < n; i++) { if (arr2.lower_bound(arr1[i]) != arr2.end() && ((arr2.lower_bound(arr1[i]))->second != -1)) { ans[i] = (arr2.lower_bound(arr1[i]))->second; (arr2.lower_bound(arr1[i]))->second = -1; } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; } return 0; }
全部评论
(1) 回帖