2 条题解

  • 1
    @ 2026-3-22 15:30:56
    #include <bits/stdc++.h>
    using namespace std;
    struct node{
    	int b,e,t;
    }a[11451];
    bool cmp(node x,node y){
    	return x.e < y.e;
    }
    int n,m,ans,sum;
    bool vis[114514];
    int main(){
    	cin >> n >> m;
    	for(int i = 0 ; i < m ; i++) cin >> a[i].b >> a[i].e >> a[i].t;
    	sort(a,a+m,cmp);
    	for(int i = 0 ; i < m ; i++){
    		sum = 0;
    		for(int j = a[i].b ; j <= a[i].e ; j++) if(vis[j]) sum++;
    		if(sum >= a[i].t) continue;
    		for(int j = a[i].e ; j >= a[i].b && sum < a[i].t ; j--) if(!vis[j]) vis[j] = true,sum++,ans++;
    	}
    	cout << ans << endl;
    	return 0;
    }
    
    • 0
      @ 2025-12-6 18:53:27
      #include <bits/stdc++.h>
      using namespace std;
      
      int n, m, ans = 0;
      
      struct line
      {
          int s, e, v;
      }a[100005];
      
      bool used[3000005];
      bool cmp(line x, line y)
      {
          return x.e < y.e;
      }
      
      int main()
      {
          cin >> n >> m;
          for (int i = 1; i <= m; i++) cin >> a[i].s >> a[i].e >> a[i].v;
          sort (a + 1, a + m + 1, cmp);
          for (int i = 1; i <= m; i++)
          {
              int k = 0;
              for (int j = a[i].s; j <= a[i].e; j++) 
              {
                  if (used[j]) k++;
              }
              if (k >= a[i].v) continue;
              for (int j = a[i].e; j >= a[i].s; j--)
              {
                  if (!used[j])
                  {
                      used[j] = 1;
                      k++;
                      ans++;
                      if (k == a[i].v) break;
                  }
              }
          }
          cout << ans << endl;
          return 0;
      }
      
      • 1

      信息

      ID
      348
      时间
      1000ms
      内存
      512MiB
      难度
      7
      标签
      递交数
      31
      已通过
      8
      上传者