aboutsummaryrefslogtreecommitdiff
path: root/codeforces/YetAnotherPromotion
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-07-28 23:49:17 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-07-28 23:49:17 +0300
commit350518c931e4a9fa8445f47f4dadc019132a7b8a (patch)
tree69b386567dd7422ca8545a96686272cc15668fa5 /codeforces/YetAnotherPromotion
parent75d27a9d569208041107785353aed66b7a50f091 (diff)
downloadcompetitive-programming-350518c931e4a9fa8445f47f4dadc019132a7b8a.tar.xz
competitive-programming-350518c931e4a9fa8445f47f4dadc019132a7b8a.zip
Solved a problem on codeforce div3(A)
Diffstat (limited to 'codeforces/YetAnotherPromotion')
-rwxr-xr-xcodeforces/YetAnotherPromotion/mainbin17832 -> 16728 bytes
-rwxr-xr-xcodeforces/YetAnotherPromotion/main.cpp109
2 files changed, 59 insertions, 50 deletions
diff --git a/codeforces/YetAnotherPromotion/main b/codeforces/YetAnotherPromotion/main
index 798f6a8..9b890d0 100755
--- a/codeforces/YetAnotherPromotion/main
+++ b/codeforces/YetAnotherPromotion/main
Binary files differ
diff --git a/codeforces/YetAnotherPromotion/main.cpp b/codeforces/YetAnotherPromotion/main.cpp
index 1bb5eb9..a772000 100755
--- a/codeforces/YetAnotherPromotion/main.cpp
+++ b/codeforces/YetAnotherPromotion/main.cpp
@@ -1,4 +1,4 @@
-#include<bits/stdc++.h>
+#include <bits/stdc++.h>
using namespace std;
using ll = long long;
@@ -10,12 +10,14 @@ using mpii = map<int, int>;
using mpll = map<ll, ll>;
using db = long double;
-#define pb push_back
+#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define lb lower_bound
#define ub upper_bound
-#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
+#define make_unique(x) \
+ sort(all((x))); \
+ (x).resize(unique(all((x))) - (x).begin())
#define ceil(a, b) ((a) + (b) - 1) / (b))
const int MOD = (int)1e9 + 7;
@@ -23,57 +25,60 @@ const db PI = acos((db)-1);
const int dx[4]{1, 0, -1, 0};
const int dy[4]{0, 1, 0, -1};
-template<typename K, typename V> ostream& operator<<(ostream& os, const pair<K, V>& p);
-template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec);
-template<typename K, typename V> ostream& operator<<(ostream& os, const map<K, V>& m);
-template<typename K, typename V> ostream& operator<<(ostream& os, const unordered_map<K, V>& m);
-template<typename T> ostream& operator<<(ostream& os, const set<T>& s);
-template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& s);
-
-template<typename K, typename V>
-ostream& operator<<(ostream& os, const pair<K, V>& p) {
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p);
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m);
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m);
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s);
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s);
+
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const pair<K, V> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
-template<typename T>
-ostream& operator<<(ostream& os, const vector<T>& vec) {
+template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (size_t i = 0; i < vec.size(); ++i) {
- if (i > 0) os << ", ";
+ if (i > 0)
+ os << ", ";
os << vec[i];
}
os << "}";
return os;
}
-
-template<typename K, typename V>
-ostream& operator<<(ostream& os, const map<K, V>& m) {
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const map<K, V> &m) {
os << "{";
- for (const auto& p : m) {
+ for (const auto &p : m) {
os << p.first << ": " << p.second << ", ";
}
os << "}";
return os;
}
-template<typename K, typename V>
-ostream& operator<<(ostream& os, const unordered_map<K, V>& m) {
+template <typename K, typename V>
+ostream &operator<<(ostream &os, const unordered_map<K, V> &m) {
os << "{";
- for (const auto& p : m) {
+ for (const auto &p : m) {
os << p.first << ": " << p.second << ", ";
}
os << "}";
return os;
}
-template<typename T>
-ostream& operator<<(ostream& os, const set<T>& s) {
+template <typename T> ostream &operator<<(ostream &os, const set<T> &s) {
int i = 0;
os << "{";
- for (const auto& e : s) {
- if (i > 0) os << ", ";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
os << e;
i++;
}
@@ -81,12 +86,13 @@ ostream& operator<<(ostream& os, const set<T>& s) {
return os;
}
-template<typename T>
-ostream& operator<<(ostream& os, const unordered_set<T>& s) {
+template <typename T>
+ostream &operator<<(ostream &os, const unordered_set<T> &s) {
int i = 0;
os << "{";
- for (const auto& e : s) {
- if (i > 0) os << ", ";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
os << e;
i++;
}
@@ -94,18 +100,13 @@ ostream& operator<<(ostream& os, const unordered_set<T>& s) {
return os;
}
-void print() {
- cerr << "\n";
-}
+void print() { cerr << "\n"; }
-template<typename T, typename... TS>
-void print(T val, TS... vals) {
+template <typename T, typename... TS> void print(T val, TS... vals) {
cerr << val << " ";
print(vals...);
}
-
-
/* stuff you should look for:
---------------------------
* special cases (n=1?)
@@ -116,27 +117,35 @@ void print(T val, TS... vals) {
*/
void solve() {
- int a, b;
- cin >> a >> b;
- int n, m;
- cin >> n >> m;
+ ll a, b, n, m;
+ cin >> a >> b >> n >> m;
+ if (m >= n) {
+ cout << min(a, b) * n << '\n';
+ return;
+ }
ll ans = 0;
- ll tmp = (a / (m + 1));
- ans += a * tmp;
- n -= tmp + (tmp / m);
- print(tmp);
- ans += min(a * n, b * n);
+ if (m < n) {
+ if ((a * m) / (m + 1) <= b) {
+ ans += (n * m / (m + 1)) * a;
+ int x = (n * m / (m + 1));
+ n -= x + x / m;
+ } else {
+ ans += b * n;
+ n = 0;
+ }
+ }
+ if (n == 1) {
+ ans += min(a, b);
+ }
cout << ans << '\n';
}
-int main () {
+int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt;
cin >> tt;
- while(tt--) {
+ while (tt--) {
solve();
}
}
-
-