• Source
    1. /**************************************************************
    2.   Problem: 2802
    3.   User: zrts
    4.   Language: C++
    5.   Result: Accepted
    6.   Time:976 ms
    7.   Memory:11192 kb
    8. ****************************************************************/
    9.  
    10. #include <cstdio>
    11. #include <cstring>
    12. #include <algorithm>
    13. #include <queue>
    14. // by zrt
    15. // problem:
    16. // 无论你在什么时候开始,重要的是开始以后就不要停止。
    17. using namespace std ;
    18. typedef long long LL ;
    19. const double eps(1e-10) ;
    20. const int inf(0x3f3f3f3f) ;
    21. struct N{
    22. LL x,w;
    23. N(LL a=0,LL b=0){
    24. x=a,w=b;
    25. }
    26. friend bool operator < (N a,N b){
    27. return a.w<b.w;
    28. }
    29. };
    30. priority_queue<N> q;
    31. bool ans[255001];
    32. LL a[255001],b[255001];
    33. int main(){
    34. #ifdef LOCAL
    35. freopen("in.txt","r",stdin) ;
    36. freopen("out.txt","w",stdout) ;
    37. #endif
    38. int n;scanf("%d",&n);
    39. LL now(0);
    40. for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    41. for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
    42. for(int i=1;i<=n;i++){
    43. now+=a[i];
    44. if(now>=b[i]){
    45. now-=b[i];q.push(N(i,b[i]));ans[i]=1;
    46. }else{
    47. if(q.empty()) continue;
    48. int big=q.top().w,x=q.top().x;
    49. if(big>b[i]) {
    50. q.pop();ans[x]=0;now+=big-b[i];
    51. q.push(N(i,b[i]));ans[i]=1;
    52. }
    53. }
    54. }
    55. int tot=0;
    56. for(int i=1;i<=n;i++) if(ans[i]) tot++;
    57. printf("%d\n",tot);
    58. for(int i=1;i<=n;i++) if(ans[i]) printf("%d ",i);
    59. return 0 ;
    60. }