新题
2024-09-06 17:54:31
发布于:广东
26阅读
0回复
0点赞
前缀和+二分查找
直接algorithm逃课
#include <iostream>
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;
int a[100005];
int read(){//快读
char c = getchar();
int x = 0, f = 1;
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)){
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * f;
}
signed main(){
int n = read();
for(int i = 1; i <= n; i++){
a[i] = read();
a[i] += a[i - 1];
}
sort(a + 1, a + n + 1);
int m = read(), x;
while(m--){
x = read();
cout << upper_bound(a + 1, a + n + 1, x) - a - 1 << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个