Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Design and analysis of algorithms / Practicum / Exam1 / 1-Flowers.cpp
diff options
context:
space:
mode:
Commitf2ac1662504c72122bf9b77fe265095b58dab575 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-04-10 09:48:06 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-04-10 09:48:06 +0300
Files90030cef9c740ce895c61e50bd3726cec2944f4a /Year 2/Design and analysis of algorithms/Practicum/Exam1/1-Flowers.cpp
uni-projects-f2ac1662504c72122bf9b77fe265095b58dab575.tar
uni-projects-f2ac1662504c72122bf9b77fe265095b58dab575.tar.gz
uni-projects-f2ac1662504c72122bf9b77fe265095b58dab575.zip
Parentfe5a64bc48dd8b440fe13883f47c8fe5938ba080 (diff)
[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.cpp25
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);
+}