F to pay respect O:)
unknown
c_cpp
4 years ago
1.6 kB
10
Indexable
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int, int>
#define pd pair<double, double>
#define vii vector<pair<int, int>>
#define ll long long
#define INF 1e9
#define EPS 1e-9
#define LSOne(S) ((S) & -(S))
#define sorted(a) sort(a.begin(),a.end())
#define reversed(a) reverse(a.begin(),a.end())
ll getPoison(string ptime,ll n){
// takes the schedule and returns the effect
ll P_effect=0;
for(ll i=0;i<n;i++){
char c=ptime[i];
if(c=='1')
P_effect+=(n-i);
}
return P_effect;
}
ll getRegeneration(string ptime,string rtime,ll n){
// takes the schedule and returns the effect
ll R_effect=0;
for(ll i=0;i<n;i++){
char c=rtime[i];
if(c=='1' && ptime[i]=='0')
R_effect+=(n-i);
}
return R_effect;
}
ll findSchedule(string rtime,ll R, ll K, ll P,ll n){
priority_queue<pair<ll,ll>> q;
for(ll i=0;i<rtime.length();i++){
if(rtime[i]=='1'){
q.push( make_pair((n-i)*(P+R),i));
}else{
q.push( make_pair((n-i)*P, i));
}
}
string ptime(n,'0');
for(ll i=0;i<K;i++){
ptime[q.top().second]='1';
q.pop();
}
return P*getPoison(ptime,n)-R*getRegeneration(ptime,rtime,n);
}
int main(){
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N,X,R,P,K;
string rtime;
cin >> N >> X >> R >> P >> K;
cin >> rtime;
ll S_effect=N*X;
ll out = findSchedule(rtime,R,K,P,N);
cout << S_effect+out << endl;
}
Editor is loading...