開啟章節選單
1203 Argus
程式碼
#include <bits/stdc++.h> using namespace std; #define int long long #define idonthavegirlfriend ios::sync_with_stdio(0), cin.tie(0); #define pb push_back #define yn(a) (a ? "Yes\n" : "No\n") // author:Jackis666 bool cmp(pair<int, int> a, pair<int, int> b) { if (a.second == b.second) { return a.first < b.first; } return a.second < b.second; } signed main() { idonthavegirlfriend string s; vector<pair<int, int>> a; while (cin >> s, s != "#") { int aa, bb; cin >> aa >> bb; a.pb({aa, bb}); } int k; cin >> k; vector<pair<int, int>> ans; for (int i = 0; i < k; i++) { for (int j = 0; j < a.size(); j++) { ans.pb({a[j].first, (i + 1) * a[j].second}); } } sort(ans.begin(), ans.end(), cmp); for (int i = 0; i < k; i++) { cout << ans[i].first << endl; } }
// author: Piau #include <bits/stdc++.h> using namespace std; #define WA() cin.tie(0)->sync_with_stdio(0) #define all(x) (x).begin(), (x).end() #define int long long #define TIII tuple<int, int, int> signed main() { WA(); string s; priority_queue<TIII, vector<TIII>, greater<TIII>> pq; while (getline(cin, s), s != "#") { stringstream ss(s); int id, w; ss >> s; ss >> id; ss >> w; pq.push({w, id, w}); } int k; for (cin >> k; k--;) { auto [t, id, w] = pq.top(); pq.pop(); cout << id << '\n'; pq.push({t + w, id, w}); } }