Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(v) for (auto &i : v) cin >> i;
- #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
- #define ll long long
- #define ull unsigned long long
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define MOD 107
- #define endl '\n'
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
- void Warding()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- /*
- STOP USING int
- */
- void solve(){
- string s; cin>>s;
- int a, b; cin>>a>>b;
- int n = s.size();
- int one = count(all(s),'1'), zero = n - one;
- ll cost1 = (one - count(s.begin(), s.begin() + one,'1'))*a;
- ll cost2 = (one - count(s.begin() + (n-one), s.end(),'1'))*a;
- ll cost3 = (zero - count(s.begin(), s.begin() + zero,'0'))*b;
- ll cost4 = (zero - count(s.begin() + (n-zero), s.end(),'0'))*b;
- cout<<min(cost1 + cost4, cost2 + cost3)<<endl;
- }
- int main()
- {
- Warding();
- int TC = 1;
- // cin >> TC;
- while (TC--)
- {
- solve();
- }
- Time
- }
Advertisement
Add Comment
Please, Sign In to add comment