社区讨论

求条 ABC C题

学术版参与者 8已保存回复 15

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
15 条
当前快照
1 份
快照标识符
@m3a7rpiq
此快照首次捕获于
2024/11/09 21:41
去年
此快照最后确认于
2024/11/10 08:18
去年
查看原帖
通过测试发现是判 -1 出了问题,但是不会调
CPP
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef pair<int , int> pi;
#define endl '\n'
const int N = 2e5 + 10;
int n , m;
pi a[N];
const __int128 c = 1;
__int128 getsum(int l) {
    return c * (l + 1) * l / 2;
}
int sum(int l , int r) {
    return getsum(r) - getsum(l - 1);
}

signed main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> m >> n;
    int s = 0;
    for (int i = 1; i <= n; i++) cin >> a[i].first;
    for (int i = 1; i <= n; i++) cin >> a[i].second , s += a[i].second;
    sort(a + 1 , a + 1 + n);
    if (s < m || a[1].first != 1) {
        cout << -1;
        return 0;
    }
    int lst = m;
    int ans = 0;
    for (int i = n; i >= 1; i--) {
        int len = min((ll)a[i].second , lst - a[i].first + 1);
        ans += sum(lst - len + 1 , lst) - len * a[i].first;
        lst = lst - len;
    }
    if (lst != 0) cout << -1;
    else {
        cout << (ll)ans << endl;
    }
    return 0;
}

回复

15 条回复,欢迎继续交流。

正在加载回复...