Editorial for Biểu thức
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của ladpro98
#include <iostream> #include <algorithm> #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define REP(i, a, b) for(int i = (a); i <=(b); ++i) const int N = 100005; using namespace std; int n, k; int a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; FOR(i, 0, n) cin >> a[i]; sort(a + 1, a + n, greater<int>()); long long ans = a[0]; REP(i, 1, k) ans += a[i]; FOR(i, k + 1, n) ans -= a[i]; cout << ans << endl; return 0; }
Comments