13302:
#include<algorithm> #include<iostream> #include<limits.h> #include<stdlib.h> #include<string.h> #include<complex> #include<cstring> #include<iomanip> #include<stdio.h> #include<bitset> #include<cctype> #include<math.h> #include<string> #include<time.h> #include<vector> #include<cmath> #include<queue> #include<stack> #include<list> #include<map> #include<set> #define LL long long using namespace std; const LL mod = 1e9 + 7; const double PI = acos(-1.0); const double E = exp(1.0); const int M = 1e6 + 5; string s; int dis[M]; int main() { LL a, b; while( cin >> a >> b ){ cin >> s; b = a - b; int len = s.size(); int sum = 0; memset(dis, 0, sizeof(dis)); for(int i = 0; i < len; ++i){ if(s[i] == 'B'){ sum++; dis[sum] = i + 1; } } if(sum == 0){ puts("0"); continue; } LL mn = 1e11; LL ans; for(int i = 0; i <= sum; ++i){ ans = (LL)(i * a); for(int j = 1; j <= sum - i; j++){ if(dis[j] > j + i) ans += (LL)(b * (dis[j] - j - i)); } mn = min(mn, ans); } cout << mn << endl; } return 0; }13308:
#include<algorithm>
#include<iostream>
#include<limits.h>
#include<stdlib.h>
#include<string.h>
#include<complex>
#include<cstring>
#include<iomanip>
#include<stdio.h>
#include<bitset>
#include<cctype>
#include<math.h>
#include<string>
#include<time.h>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#define LL long long
using namespace std;
const LL mod = 1e9 + 7;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int M = 1e3 + 5;
int a[M];
int main()
{
int n;
while( cin >> n ){
for(int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
int mn = 1e9;
int ans;
for(int i = 0; i <= n / 2; ++i){
ans = 0;
for(int j = 0; j < i; ++j){
ans += 24 - a[n - j - 1] + a[j];
}
for(int j = i; j < n - i; j += 2){
ans += a[j + 1] - a[j];
}
mn = min(mn, ans);
}
cout << mn << endl;
}
return 0;
}