Page 1 of 1
1121 - Subsequence
Posted: Sat Jan 25, 2014 5:24 pm
by holigan187
Code: Select all
//Nguyen Duc Anh
//1121
#include<iostream>
#include<fstream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<map>
#define fi "1121.inp"
#define fo "1121.out"
using namespace std;
long n;
long s[100005];
long goc;
int tong[100005];
void input()
{
long i;
for (i=1;i<=n;i++)
scanf("%ld",&s[i]);
}
long tinh(int vt,int size)
{
if ( size == 0 )
tong[vt]=s[vt];
else
tong[vt]=tong[vt]+s[vt+size];
return tong[vt];
}
void solve()
{
long i,size;
for (size=0;size<n;size++)
{
for (i=1;i<=n;i++)
{
if ( size + i > n )
break;
if ( tinh(i,size) >= goc )
{
printf("%ld\n",size+1);
return;
}
}
}
printf("0\n");
}
int main()
{
//freopen(fi,"r",stdin);
//freopen(fo,"w",stdout);
while (scanf("%ld %ld",&n,&goc) > 0 )
{
input();
solve();
}
return 0;
}
i dont know why still WA , who can give me some critical in/out ? ty so much
Re: 1121 - WA
Posted: Mon Jan 27, 2014 10:38 pm
by brianfry713
That code gets TLE. Try solving it in O(N).
Re: 1121 - Subsequence
Posted: Sun Jun 07, 2015 8:44 pm
by Repon kumar Roy
Use Sliding Window to get AC

1121 - Subsequence
Posted: Tue Oct 06, 2015 3:01 am
by Kazi_Tanvir_Ahsan
I really need to know why the sample output is wrong for this problem. Unless I miss something from the below link:
https://uva.onlinejudge.org/index.php?o ... oblem=3562
The sample input is:
5 11
1 2 3 4 5
The sample output:
5
Should it be 3 instead of 5??
Kind Regards
Kazi
Re: 1121 - Subsequence
Posted: Wed Oct 07, 2015 5:15 pm
by uDebug
Kazi_Tanvir_Ahsan wrote:I really need to know why the sample output is wrong for this problem. Unless I miss something from the below link:
https://uva.onlinejudge.org/index.php?o ... oblem=3562
The sample input is:
5 11
1 2 3 4 5
The sample output:
5
Should it be 3 instead of 5??
Kind Regards
Kazi
Yes, you're right. Thanks for sharing. It should be
instead of
If you're in doubt, please check
http://www.udebug.com/UVa/1121
Re: 1121 - Subsequence
Posted: Sun Jun 19, 2016 6:42 pm
by hquilo
Just in case: you need to output 0 in case there is no such a subsequence with sum at least s.