A
link
暴力寻找\(2\)及以后比\(a_1\)大的数。
点击查看代码
#include<bits/stdc++.h>using namespace std;int n;
int a[105];signed main(){cin >> n;for(int i = 1;i <= n;++ i)cin >> a[i];for(int i = 2;i <= n;++ i){if(a[i] > a[1]){cout << i;return 0;}}cout << -1;return 0;}
B
link
模拟即可。
点击查看代码
#include<bits/stdc++.h>using namespace std;int n,k;
int a[105];
int cn,ans = 1;signed main(){cin >> n >> k;for(int i = 1;i <= n;++ i)cin >> a[i];for(int i = 1;i <= n;++ i){if(cn+a[i] <= k) cn += a[i];else ans++,cn = a[i];}cout << ans;return 0;}