一. 题意
买二送一。排序之后隔三求和,求折扣的最大值。
二. 代码
1 // 2 // main.cpp 3 // sicily-1438 4 // 5 // Created by ashley on 14-11-7. 6 // Copyright (c) 2014年 ashley. All rights reserved. 7 // 8 9 #include <iostream> 10 #include <algorithm> 11 using namespace std; 12 13 int prices[20000]; 14 15 int main(int argc, const char * argv[]) 16 { 17 int cases , items; 18 cin >> cases; 19 while (cases--) { 20 cin >> items; 21 for (int i = 0; i < items; i++) { 22 cin >> prices[i]; 23 } 24 sort(prices, prices + items); 25 int sum = 0; 26 for (int i = items - 3; i >= 0; i = i - 3) { 27 sum = sum + prices[i]; 28 } 29 cout << sum << endl; 30 } 31 32 return 0; 33 }
时间: 2024-10-15 01:14:10