Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
139287 | 吴晨曦 | K 次取反后最大化的数组和 | C++ | 通过 | 100 | 0 MS | 256 KB | 417 | 2024-03-22 23:58:14 |
#include <bits/stdc++.h> using namespace std; int main() { vector <int> c; int n, m; cin >> n >> m; for (int i = 1, x; i <= n; i++) cin >> x, c.insert(upper_bound(c.begin(), c.end(), x), x); while (m--) { int tmp = c[0]; c.erase(c.begin()); tmp = -tmp; c.insert(upper_bound(c.begin(), c.end(), tmp), tmp); } int s = 0; for (auto p : c) s += p; cout << s << endl; return 0; }