fork download
  1. #include <bits/stdc++.h>
  2. #define FastIO ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4.  
  5. int imos[500'001];
  6.  
  7. int main() {
  8. FastIO
  9. int n, h;
  10. cin >> n >> h;
  11. for (int i = 0; i < n; i++) {
  12. int size;
  13. cin >> size;
  14. if (i & 1) { //종유석
  15. imos[h - size + 1] += 1;
  16. } else { //석순
  17. imos[1] += 1;
  18. imos[size + 1] -= 1;
  19. }
  20. }
  21.  
  22. for (int i = 1; i <= h; i++) {
  23. imos[i] += imos[i - 1];
  24. }
  25.  
  26. int lo = n;
  27. int num = 1;
  28. for (int i = 1; i <= h; i++) {
  29. if (lo > imos[i]) {
  30. lo = imos[i];
  31. num = 1;
  32. } else if (lo == imos[i]) {
  33. num += 1;
  34. }
  35. }
  36. cout << lo << ' ' << num;
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5308KB
stdin
14 5
1
3
4
2
2
4
3
4
3
3
3
2
3
3
stdout
7 2