比赛 20170919普及组 评测结果 AAAAAAAAAA
题目名称 划分数列 最终得分 100
用户昵称 玉带林中挂 运行时间 0.036 s
代码语言 C++ 内存使用 0.67 MiB
提交时间 2017-09-19 21:06:48
显示代码纯文本
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <algorithm>
  4. #include <list>
  5. #include <queue>
  6. #include <vector>
  7. #include <ctype.h>
  8. using namespace std;
  9. #define MAXN 100011
  10. int fast_read()
  11. {
  12. int r = 0;
  13. char c;
  14. bool sig = false;
  15. while(c = getchar())
  16. {
  17. if(c >= '0' && c <= '9')
  18. {
  19. r = c^0x30;
  20. break;
  21. }else if(c == '-')
  22. sig = true;
  23. }
  24. while(isdigit(c = getchar()))
  25. r = (r<<3)+(r<<1)+(c^0x30);
  26. if(sig)return -r;
  27. return r;
  28. }
  29. int n, t;
  30. int sum[MAXN];
  31. bool check(int m)
  32. {
  33. int cnt = 0;
  34. int last = 1;
  35. for(int i = 1; i <= n; i++)
  36. {
  37. if(sum[i] - sum[i-1] > m)return false;
  38. if(sum[i] - sum[last-1] > m)
  39. {
  40. cnt++;
  41. last = i;
  42. }
  43. }
  44. return cnt < t;
  45. }
  46. int main()
  47. {
  48. freopen("seqa.in", "r", stdin);
  49. freopen("seqa.out", "w", stdout);
  50. scanf("%d %d", &n, &t);
  51. for(int i = 1; i <= n; i++)
  52. sum[i] = sum[i-1]+fast_read();
  53. int l = 0, r = 0x7fffffff;
  54. int ans;
  55. while(l <= r)
  56. {
  57. int m = (l+r)>>1;
  58. if(check(m))ans = m, r = m-1;
  59. else l = m+1;
  60. }
  61. printf("%d\n", ans);
  62. return 0;
  63. }