版本比较
题解:P16430 危机重重
正文
增加 12 行删除 12 行
46 行未改动47484950515251525354555656575859603 行未改动6465666768686970717273747576767778798081818283848546 行未改动1321331341351361371361371381391401411411421431441453 行未改动1491501511521531531541551561571581591601611611621631641651661661671681691706 行未改动46 行未改动int main(){ cin >> n >> k; people.resize(n); for (int i = 0; i < n; ++i)
for (int i = 0; i < n; ++i) { cin >> people[i].first; } for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i) { cin >> people[i].second; } sort(people.begin(), people.end());3 行未改动 long long target = people[i].first; vector<long long> costs; costs.reserve(i + 1);
for (int j = 0; j <= i; ++j) for (int j = 0; j <= i; ++j) { costs.push_back((target - people[j].first) * people[j].second); }
nth_element(costs.begin(), costs.begin() + k, costs.end());
long long cur = 0; for (int j = 0; j < k; ++j) for (int j = 0; j < k; ++j) { cur += costs[j]; }
if (ans == -1 || cur < ans) if (ans == -1 || cur < ans) { ans = cur; } }46 行未改动{ n = read(); k = read(); people.resize(n); for (int i = 0; i < n; ++i)
for (int i = 0; i < n; ++i) { people[i].first = read(); } for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i) { people[i].second = read(); } sort(people.begin(), people.end());3 行未改动 int128 target = people[i].first; vector<int128> costs; costs.reserve(i + 1);
for (int j = 0; j <= i; ++j) for (int j = 0; j <= i; ++j) { costs.push_back((target - people[j].first) * people[j].second); }
nth_element(costs.begin(), costs.begin() + k, costs.end());
int128 cur = 0; for (int j = 0; j < k; ++j) for (int j = 0; j < k; ++j) { cur += costs[j]; }
if (ans == -1 || cur < ans) if (ans == -1 || cur < ans) { ans = cur; } }6 行未改动