- 问答
龙虎斗20分钟就28分,这题有实力
- 2023-11-26 11:07:17 @
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int m, p1, s1, s2;
cin >> m >> p1 >> s1 >> s2;
long long dragonPower = 0, tigerPower = 0;
for (int i = 0; i < n; i++) {
if (i < m-1) {
dragonPower += c[i] * (m-1 - i);
} else if (i > m-1) {
tigerPower += c[i] * (i - m+1);
}
}
if (m-1 < p1-1) {
dragonPower += s1 * (p1-1 - m+1);
} else if (m-1 > p1-1) {
tigerPower += s1 * (m-1 - p1-1);
}
long long minDiff = abs(dragonPower - tigerPower);
int minIndex = p1;
for (int i = 0; i < n; i++) {
if (i == m-1) continue;
long long newDragonPower = dragonPower, newTigerPower = tigerPower;
if (i < p1-1) {
newDragonPower += s2 * (p1-1 - i);
} else if (i > p1-1) {
newTigerPower += s2 * (i - p1-1);
}
long long diff = abs(newDragonPower - newTigerPower);
if (diff < minDiff) {
minDiff = diff;
minIndex = i+1;
}
}
cout << minIndex << endl;
return 0;
}
0 comments
No comments so far...