Hdu4221-Greedy?

Source: Internet
Author: User
Tags bitset

Use C ++ to input and output TLE, and use % lld to output WA and % i64d to output

No traps

 

[Html]
// File Name: hdu4221.cpp
// Author: bo_jwolf
// Created Time: Wednesday, May 08,201 3 PM01: 15: 20 HKT
 
# Include <vector>
# Include <list>
# Include <map>
# Include <set>
# Include <deque>
# Include <stack>
# Include <queue>
# Include <bitset>
# Include <algorithm>
# Include <functional>
# Include <numeric>
# Include <utility>
# Include <sstream>
# Include <iostream>
# Include <iomanip>
# Include <cstdio>
# Include <cmath>
# Include <cstdlib>
# Include <cstring>
# Include <ctime>
 
Using namespace std;
Typedef long ll;
Const int maxn = 100005;
Struct node
{
Int a, B;
} Edge [maxn];
 
Bool cmp (node x, node y)
{
Return x. B <y. B;
}
 
Int main ()
{
Int t, n;
Int k = 0;
Scanf ("% d", & t );
While (t --)
{
K ++;
Scanf ("% d", & n );
For (int I = 0; I <n; I ++)
Scanf ("% d", & edge [I]. a, & edge [I]. B );
Long sum = 0;
Long ans = 0;
Sort (edge, edge + n, cmp );
For (int I = 0; I <n; I ++)
{
Sum + = edge [I].;
If (sum-edge [I]. B> ans)
Ans = sum-edge [I]. B;
}
Printf ("Case % d: % I64d \ n", k, ans );
}
Return 0;
}

// File Name: hdu4221.cpp
// Author: bo_jwolf
// Created Time: Wednesday, May 08,201 3 PM01: 15: 20 HKT

# Include <vector>
# Include <list>
# Include <map>
# Include <set>
# Include <deque>
# Include <stack>
# Include <queue>
# Include <bitset>
# Include <algorithm>
# Include <functional>
# Include <numeric>
# Include <utility>
# Include <sstream>
# Include <iostream>
# Include <iomanip>
# Include <cstdio>
# Include <cmath>
# Include <cstdlib>
# Include <cstring>
# Include <ctime>

Using namespace std;
Typedef long ll;
Const int maxn = 100005;
Struct node
{
Int a, B;
} Edge [maxn];

Bool cmp (node x, node y)
{
Return x. B <y. B;
}

Int main ()
{
Int t, n;
Int k = 0;
Scanf ("% d", & t );
While (t --)
{
K ++;
Scanf ("% d", & n );
For (int I = 0; I <n; I ++)
Scanf ("% d", & edge [I]. a, & edge [I]. B );
Long sum = 0;
Long ans = 0;
Sort (edge, edge + n, cmp );
For (int I = 0; I <n; I ++)
{
Sum + = edge [I].;
If (sum-edge [I]. B> ans)
Ans = sum-edge [I]. B;
}
Printf ("Case % d: % I64d \ n", k, ans );
}
Return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.