From 9ee5e675145379cf11ca8545649e534bf6834941 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 21 Oct 2020 21:27:03 +0800 Subject: [PATCH] P3131 [USACO16JAN] Subsequences Summing to Sevens S R40246968 --- problem/P3131/P3131.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 problem/P3131/P3131.cpp diff --git a/problem/P3131/P3131.cpp b/problem/P3131/P3131.cpp new file mode 100644 index 00000000..bc5495b1 --- /dev/null +++ b/problem/P3131/P3131.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +long long a[50005]; + +int main() { + int n, k; + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> k; + a[i] = a[i - 1] + k; + } + for (int i = n; i > 0; i--) { + for (int j = 1; j + i <= n; j++) { + if ((a[i + j] - a[j]) % 7 == 0) { + cout << i << endl; + return 0; + } + } + } + cout << 0 << endl; + return 0; +}