2 条题解

  • 1
    @ 2026-7-9 9:00:39
    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
    	int a[100005];
    	int n, b;
    	cin >> n >> b;
    	for (int i = 1; i <= n; i++) {
    		cin >> a[i];
    
    	}
    	for (int j = 1; j <= n; j++) {
    		b = b - a[j];
    		if (b <= 0) {
    			cout << j;
    			break;
    		}
    	}
    	if (b > 0) {
    		cout << "-1";
    	}
    
    	return 0;
    }
    
    
    • 0
      @ 2025-7-16 15:43:40

      #include <bits/stdc++.h> using namespace std;

      int main() { int a[100005]; int n, b; cin >> n >> b; for (int i = 1; i <= n; i++) { cin >> a[i];

      }
      for (int j = 1; j <= n; j++) {
      	b = b - a[j];
      	if (b <= 0) {
      		cout << j;
      		break;
      	}
      }
      if (b > 0) {
      	cout << "-1";
      }
      
      return 0;
      

      }

      • 1

      信息

      ID
      336
      时间
      1000ms
      内存
      64MiB
      难度
      4
      标签
      递交数
      144
      已通过
      63
      上传者