2 条题解

  • 0
    @ 2025-10-8 16:59:33
    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    struct node
    {
        int p, t, used; //赠票的价格,最晚使用时间和是否需用过
    }q[N];
    int main()
    {
        int n, ans=0; scanf("%d", &n);
        for(int i=1, op, p, t, head=1, tail=0; i<=n; i++)
        {
            scanf("%d%d%d", &op, &p, &t);
            if(op==0)
            {
                ans += p;
                q[++tail] = {p, t+45, 0};
            }
            else
            {
                while(head <= tail && (q[head].t < t || q[head].used == 1)) head++;
                bool bk = 0;
                for(int j=head; j<=tail; j++)
                    if (q[j].p >= p && q[j].used == 0)
                    {
                        bk = 1;
                        q[j].used = 1;
                        break;
                    }
                if(!bk) ans += p;
            }
        }
        printf("%d\n", ans);
        return 0;
    }
    
    • 0
      @ 2025-10-8 16:59:27
      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e5+10;
      struct node
      {
          int p,t,used;//赠票的价格,最晚使用时间和是否需用过
      }q[N];
      int main()
      {
          int n,ans=0;scanf("%d",&n);
          for(int i=1,op,p,t,head=1,tail=0;i<=n;i++)
          {
              scanf("%d%d%d",&op,&p,&t);
              if(op==0)
              {
                  ans+=p;
                  q[++tail]={p,t+45,0};
              }
              else
              {
                  while(head<=tail && (q[head].t<t || q[head].used==1))head++;
                  bool bk=0;
                  for(int j=head;j<=tail;j++)
                      if (q[j].p>=p && q[j].used==0)
                      {
                          bk=1;
                          q[j].used=1;
                          break;
                      }
                  if(!bk) ans+=p;
              }
          }
          printf("%d\n",ans);
          return 0;
      }
      • 1

      信息

      ID
      1991
      时间
      1000ms
      内存
      250MiB
      难度
      4
      标签
      递交数
      37
      已通过
      20
      上传者