diff options
[DAA/E1] Added work from first exam from yesterday
1 files changed, 25 insertions, 0 deletions
| -rw-r--r-- | Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp | 25 |
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp b/Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp new file mode 100644 index 0000000..9421332 --- /dev/null +++ b/Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp @@ -0,0 +1,25 @@ +#include <cstdio> +#include <cmath> +#include <vector> +#include <algorithm> +using namespace std; + +int main() { + int K = 0, N = 0; + scanf("%d %d", &N, &K); + vector<int> f; + int temp = 0; + for (int i = 0; i < N; i++) { + scanf("%d", &temp); + f.push_back(temp); + } + + sort(f.rbegin(), f.rend()); + long S = 0, p = 1; + for (int i = 0; i < f.size(); i++) { + if (i == K * p) p++; + S += p * f[i]; + } + + printf("%ld", S); +} |
