題目描述:
爲了用事實說明挖掘機技術到底哪家強,PAT 組織了一場挖掘機技能大賽。現請你根據比賽結果統計出技術最強的那個學校。
輸入格式:
輸入在第 1 行給出不超過 105的正整數 N,即參賽人數。隨後 N 行,每行給出一位參賽者的信息和成績,包括其所代表的學校的編號(從 1 開始連續編號)、及其比賽成績(百分制),中間以空格分隔。
輸出格式:
在一行中給出總得分最高的學校的編號、及其總分,中間以空格分隔。題目保證答案唯一,沒有並列。
輸入樣例:
6
3 65
2 80
1 100
2 70
3 40
3 0
輸出樣例:
2 150
代碼:
- C++
#include<iostream>
using namespace std;
int main() {
int a[1000000]={0};
int n,x,y;
int max=0;
cin>>n;
for(int i=0;i<n;i++) {
cin>>x>>y;
a[x]+=y;
if(a[x]>a[max]) {
max=x;
}
}
cout<<max<<" "<<a[max]<<endl;
return 0;
}
- Python
def main():
n=int(input())
m=[0]*1000000
index=0
for i in range(n):
a,b=map(int,input().split())
m[a]+=b
if m[a]>m[index]:
index=a
print(index,m[index])
if '__name__'==main():
main()
不知道爲什麼Python的最後一個測試樣例超時,Python運行較慢?