超时无数次,求指点

hebaijun 2024-04-28 22:19:43 10

#include <bits/stdc++.h> using namespace std; int main() { freopen("B.in", "r", stdin); freopen("B.out", "w", stdout); int n, m, a[1000000], h = 0,h1=0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n-1; i++) { for (int j = i + 1; j < n; j++) { if(a[i]+a[i+1]>m){ h1++; } if (a[i] + a[j] <= m) { h++; } else { break; } } if(h1==1){ break; } } printf("%d", h); return 0; }

{{ vote && vote.total.up }}

共 1 条回复

root 站长

双重循环 变 一重就过了