1. 程式人生 > >51Nod 1094 和為k的連續區間 | 水

51Nod 1094 和為k的連續區間 | 水

sin std fin turn 技術分享 pac += str ima

技術分享

Input示例
6 10
1
2
3
4
5
6
Output示例
1 4
#include "cstdio"
#include "algorithm"
#include "iostream"
#include "set"
using namespace std;
#define LL long long
#define N 10010
int arr[N];
int main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k)){
        for(int i=0;i<n;i++){
            scanf("
%d",&arr[i]); } LL sum=0; int a=1,b=1; bool c=0; for(int i=0;i<n;i++){ sum=arr[i];a=i+1; for(int j=i+1;j<n;j++){ if(sum==k) { c=1; break; } sum
+=arr[j];b=j+1; } if(c) break; } if(!c) printf("No Solution\n"); else printf("%d %d\n",a,b); } return 0; }

51Nod 1094 和為k的連續區間 | 水