1 solutions
-
0
C++ :
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> score[N + 2], a, b; bool cmp(int i, int j) { return i > j; } int main() { int m, n, k; cin >> m >> n >> k; a.resize(n), b.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { cin >> b[i]; score[a[i]].emplace_back(b[i]); } vector<int> need(m + 2); int ans = 0, mx_meed = 0, mx_need_i = -1; for (int i = 1; i <= m; i++) { sort(score[i].begin(), score[i].end(), cmp); int sum = 0; for (int j = 0; j < (int)score[i].size(); j++) { sum += score[i][j]; if (sum >= k) { need[i] = j + 1; break; } } if (sum < k) { puts("-1"); return 0; } ans += need[i]; if (need[i] > mx_meed) { mx_meed = need[i], mx_need_i = i; } } if (mx_meed - 1 <= ans - mx_meed) { cout << ans << endl; return 0; } int last = 0; for (int i = 1; i <= m; i++) if (i!= mx_need_i) last += score[i].size() - need[i]; cout << (mx_meed - 1 <= ans - mx_meed - last? ans - last : -1) << endl; return 0; }
- 1
Information
- ID
- 112
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By