Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yurahuna
Created September 20, 2016 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurahuna/a887faae0edca0ecb74f8ee7d105fd59 to your computer and use it in GitHub Desktop.
Save yurahuna/a887faae0edca0ecb74f8ee7d105fd59 to your computer and use it in GitHub Desktop.
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
cin >> n;
vi c(3);
rep(i, n) {
int a;
cin >> a;
c[a%3]++;
}
int ans = 1;
if (c[1] > 0) {
// 1から使うとき
int c1 = c[1], c2 = c[2];
int t = c[0] + 1; c1--;
int x = min(c1, c2);
t += 2 * x; c1 -= x; c2 -= x;
t += max(min(c1, 2), min(c2, 1));
ans = max(ans, t);
}
if (c[2] > 0) {
// 2から使うとき
int c1 = c[1], c2 = c[2];
int t = c[0] + 1; c2--;
int x = min(c1, c2);
t += 2 * x; c1 -= x; c2 -= x;
t += max(min(c2, 2), min(c1, 1));
ans = max(ans, t);
}
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment