#include <cstdio> #define SUM(i) (i+1)*(i)/2 using namespace std; int n,k,x,res=2020; int main() { scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) { scanf("%d",&x); int el = SUM(i) - SUM(j-1) - SUM(i-j); if(el <= k && res > x) res = x; } printf("%d\n",res); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <cstdio> #define SUM(i) (i+1)*(i)/2 using namespace std; int n,k,x,res=2020; int main() { scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) { scanf("%d",&x); int el = SUM(i) - SUM(j-1) - SUM(i-j); if(el <= k && res > x) res = x; } printf("%d\n",res); return 0; } |