Editing
2015 Dec Bronze Problem 2 Speeding Ticket
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Code == === C++ === <pre> #include <iostream> #include <fstream> #include <vector> using namespace std; int main() { ifstream input("speeding.in"); ofstream output("speeding.out"); int n, m; input >> n >> m; vector<int> speedLimits(100, 0); int currentMile = 0; for (int i = 0; i < n; i++) { int segmentLength, speedLimit; input >> segmentLength >> speedLimit; for (int j = 0; j < segmentLength; j++) { speedLimits[currentMile++] = speedLimit; } } vector<int> bessieSpeeds(100, 0); currentMile = 0; for (int i = 0; i < m; i++) { int segmentLength, speed; input >> segmentLength >> speed; for (int j = 0; j < segmentLength; j++) { bessieSpeeds[currentMile++] = speed; } } int maxSpeedOverLimit = 0; for (int i = 0; i < 100; i++) { int exceededSpeed = bessieSpeeds[i] - speedLimits[i]; maxSpeedOverLimit = max(maxSpeedOverLimit, exceededSpeed); } output << maxSpeedOverLimit << endl; output.close(); return 0; } </pre> === Java === <pre> import java.io.*; import java.util.*; public class Speeding { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new FileReader("speeding.in")); PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("speeding.out"))); StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); int n = Integer.parseInt(tokenizer.nextToken()); int m = Integer.parseInt(tokenizer.nextToken()); int[] speedLimits = new int[100]; int currentMile = 0; for (int i = 0; i < n; i++) { tokenizer = new StringTokenizer(reader.readLine()); int segmentLength = Integer.parseInt(tokenizer.nextToken()); int speedLimit = Integer.parseInt(tokenizer.nextToken()); for (int j = 0; j < segmentLength; j++) { speedLimits[currentMile++] = speedLimit; } } int[] bessieSpeeds = new int[100]; currentMile = 0; for (int i = 0; i < m; i++) { tokenizer = new StringTokenizer(reader.readLine()); int segmentLength = Integer.parseInt(tokenizer.nextToken()); int speed = Integer.parseInt(tokenizer.nextToken()); for (int j = 0; j < segmentLength; j++) { bessieSpeeds[currentMile++] = speed; } } int maxSpeedOverLimit = 0; for (int i = 0; i < 100; i++) { int exceededSpeed = bessieSpeeds[i] - speedLimits[i]; maxSpeedOverLimit = Math.max(maxSpeedOverLimit, exceededSpeed); } writer.println(maxSpeedOverLimit); writer.close(); } } </pre> === Python === <pre> with open("speeding.in", "r") as input: n, m = map(int, input.readline().split()) speed_limits = [0] * 100 current_mile = 0 for _ in range(n): segment_length, speed_limit = map(int, input.readline().split()) for _ in range(segment_length): speed_limits[current_mile] = speed_limit current_mile += 1 bessie_speeds = [0] * 100 current_mile = 0 for _ in range(m): segment_length, speed = map(int, input.readline().split()) for _ in range(segment_length): bessie_speeds[current_mile] = speed current_mile += 1 max_speed_over_limit = 0 for i in range(100): exceeded_speed = bessie_speeds[i] - speed_limits[i] max_speed_over_limit = max(max_speed_over_limit, exceeded_speed) with open("speeding.out", "w") as output: output.write(str(max_speed_over_limit) + "\n") </pre> [[Category:Yearly_2015_2016]] [[Category:Bronze]] [[Category:Arrays]] [[Category:Simulation]]
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information