fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int Answer (vector <int> &Input, int K)
  6. {
  7. int Sum = 0;
  8. vector <int> Sum_Array;
  9. for (int i = 0; i < Input.size(); i++)
  10. {
  11. Sum = Sum + Input[i];
  12. Sum_Array.push_back(Sum);
  13. }
  14. int answer = 0;
  15. if (Sum_Array[0] == K)
  16. {
  17. answer = 1;
  18. }
  19. for (int i = 0; i<Input.size(); i++)
  20. {
  21. for (int j = 0; j < i; j++)
  22. {
  23. if ((Sum_Array[i] - Sum_Array[j] == K) && (i - j > answer))
  24. {
  25. answer = i - j;
  26. }
  27. }
  28. }
  29. return answer;
  30. }
  31.  
  32. int main(){
  33. int N, K;
  34. cin>>N;
  35. vector <int> Input;
  36. for (int i = 0; i < N; i++)
  37. {
  38. int value;
  39. cin>>value;
  40. Input.push_back(value);
  41. }
  42. cin>>K;
  43. int a = Answer (Input, K);
  44. cout << a;
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5316KB
stdin
5
3
3
2
1
1
1
stdout
1