版本比较
题解:P16430 危机重重
正文
增加 12 行删除 12 行
46 行未改动47484950515253545556575859603 行未改动6465666768697071727374757677787980818283848546 行未改动1321331341351361371381391401411421431441453 行未改动1491501511521531541551561571581591601611621631641651661671681691706 行未改动46 行未改动int main(){cin >> n >> k;people.resize(n);for (int i = 0; i < n; ++i){cin >> people[i].first;}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){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){cur += costs[j];}if (ans == -1 || cur < ans){ans = cur;}}46 行未改动{n = read();k = read();people.resize(n);for (int i = 0; i < n; ++i){people[i].first = read();}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){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){cur += costs[j];}if (ans == -1 || cur < ans){ans = cur;}}6 行未改动46 行未改动47484950515253545556575859603 行未改动6465666768697071727374757677787980818283848546 行未改动1321331341351361371381391401411421431441453 行未改动1491501511521531541551561571581591601611621631641651661671681691706 行未改动46 行未改动int main(){cin >> n >> k;people.resize(n);for (int i = 0; i < n; ++i){cin >> people[i].first;}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){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){cur += costs[j];}if (ans == -1 || cur < ans){ans = cur;}}46 行未改动{n = read();k = read();people.resize(n);for (int i = 0; i < n; ++i){people[i].first = read();}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){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){cur += costs[j];}if (ans == -1 || cur < ans){ans = cur;}}6 行未改动