3 条题解

  • 1
    @ 2025-4-15 18:11:17
    #include<iostream>
    #include<algorithm>
    
    using namespace std;
    typedef pair<int,int> PII;
    
    const int N=500010;
    int n;
    PII a[N];
    
    int main()
    {
        cin >> n;
        for(int i=0;i<n;i++)
        {
            int p,q;
            cin >> p >> q;
            a[i]={p+q,p};        
        }
        
        sort(a,a+n);
    
        int res=-2e9,m=0;
        for(int i=0;i<n;i++)
        {
            int l=a[i].second,r=a[i].first-a[i].second;
            res=max(res,m-r);
            m+=l;
        }
        
        cout << res << endl;
        return 0;
    }
    
    
    
    • -1
      @ 2021-12-3 18:31:18
      #include<iostream>
      #include<algorithm>
      
      using namespace std;
      typedef pair<int,int> PII;
      
      const int N=500010;
      int n;
      PII a[N];
      
      int main()
      {
          cin >> n;
          for(int i=0;i<n;i++)
          {
              int p,q;
              cin >> p >> q;
              a[i]={p+q,p};        
          }
          
          sort(a,a+n);
      
          int res=-2e9,m=0;
          for(int i=0;i<n;i++)
          {
              int l=a[i].second,r=a[i].first-a[i].second;
              res=max(res,m-r);
              m+=l;
          }
          
          cout << res << endl;
          return 0;
      }
      
      • -1
        @ 2021-8-7 19:00:37

        C++ :

        #include<iostream>
        #include<algorithm>
        
        using namespace std;
        typedef pair<int,int> PII;
        
        const int N=500010;
        int n;
        PII a[N];
        
        int main()
        {
            cin >> n;
            for(int i=0;i<n;i++)
            {
                int p,q;
                cin >> p >> q;
                a[i]={p+q,p};        
            }
            
            sort(a,a+n);
        
            int res=-2e9,m=0;
            for(int i=0;i<n;i++)
            {
                int l=a[i].second,r=a[i].first-a[i].second;
                res=max(res,m-r);
                m+=l;
            }
            
            cout << res << endl;
            return 0;
        }
        
        • 1

        信息

        ID
        36
        时间
        1000ms
        内存
        128MiB
        难度
        1
        标签
        递交数
        103
        已通过
        69
        上传者