Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #define dprint(v) cerr << #v"=" << v << endl
- using namespace std;
- #define forn(i,n) for(int i=0;i<int(n);i++)
- #define MAXN 100000
- int persona[MAXN];
- typedef int ll;
- int n, k, m, v;
- ll suma;
- ll f (int i){
- return persona[(i+1)%n] - persona[i];
- }
- bool solve(){
- m = __gcd(n,k);
- v = n / m;
- ll acumtotal = 0;
- forn (i,m){
- ll acum = 0, mini = 0, actual = 0, pos = i;
- forn (j,v){
- actual += f(pos);
- acum += actual;
- mini = min (actual, mini);
- pos = (pos + k)%n;
- }
- if (actual != 0) return false; // No es cíclico.
- acum -= mini * v;
- acumtotal += acum;
- }
- if (acumtotal*k > suma) return false; // Necesitamos Negativos
- if ((suma) % k != 0) return false; // Necesitamos racionales
- return true;
- }
- int main(){
- cin >> n >> k;
- suma = 0;
- forn (i,n) {
- cin >> persona[i];
- suma += persona[i];
- }
- if (solve ()) cout << "S" << endl;
- else cout << "N" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement