求助
查看原帖
求助
583125
XilyFe楼主2022/1/8 17:58
#include<bits/stdc++.h>
#define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
const int N = 1e6 + 10;


int n,k,t;
int x[N];
int main() {
    io_opt;
    ll ans = 0;
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> t;
        ans += (i % 2 ? t : -t);
    }
    for(int i=1;i<=k;i++) cin >> x[i];
    int op = k % 2; // 0为Bob 1为Alice
    for(int i=1;i<=k;i++){
        if(i%2 == op){ //最后一个人:绝对值变大
            if(op) ans = abs(ans) + x[i];
            else ans = -abs(ans) - x[i];
        }
        else{ //不是最后一个人:绝对值变小
            ans = abs(ans) - x[i];
        }
    }
    cout << ans << endl;
    return 0;
}

代码如上,一个测试点都没过

2022/1/8 17:58
加载中...