[Codeforces] Sereja and Coat Rack
http://codeforces.com/problemset/problem/368/A
足以秒杀的一道题.
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 5 int a[110] = {0}; 6 7 int main() 8 { 9 int n = 0, d = 0; 10 scanf("%d%d", &n, &d); 11 for (int i = 0; i < n; ++i) { 12 scanf("%d", &a[i]); 13 } 14 int m = 0; 15 scanf("%d", &m); 16 int re = 0; 17 sort(a, a + n); 18 int t = 0; 19 if (m < n) { 20 t = m; 21 } else { 22 t = n; 23 re -= d * (m - n); 24 } 25 for (int i = 0; i < t; ++i) { 26 re += a[i]; 27 } 28 printf("%d\n", re); 29 return 0; 30 }