#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); int amount, number, size = 0; vector<int> numbers; cin >> amount; size = (1 + amount) * amount / 2; numbers.reserve(15); for (int i = 0; i < size; i++){ cin >> number; numbers.push_back(number); } sort(numbers.begin(), numbers.end()); number = 0; for (int i = 0; i<amount; i++) number += numbers[i]; cout << number; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); int amount, number, size = 0; vector<int> numbers; cin >> amount; size = (1 + amount) * amount / 2; numbers.reserve(15); for (int i = 0; i < size; i++){ cin >> number; numbers.push_back(number); } sort(numbers.begin(), numbers.end()); number = 0; for (int i = 0; i<amount; i++) number += numbers[i]; cout << number; } |